{"id":387995,"date":"2024-06-29T07:40:07","date_gmt":"2024-06-29T07:40:07","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=387995"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=387995","title":{"rendered":"<span>7 \u0438 1\/2 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u043a \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0432 Python<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0442\u0438\u043f\u043e\u0432 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 Python \u0433\u0438\u0431\u043a\u0438\u043c \u0438 \u043d\u0435\u044f\u0432\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c. \u0412 Python \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 Python 3 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u043c\u043e\u0434\u0443\u043b\u044c <sup>1<\/sup><a href=\"https:\/\/docs.python.org\/3.9\/library\/typing.html\" rel=\"noopener noreferrer nofollow\">typing<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043e\u043a \u0442\u0438\u043f\u043e\u0432 \u0432\u043e \u0432\u0440\u0435\u043c\u044f  <sup>2<\/sup>\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u041d\u043e \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0435\u0434\u0438\u043d\u043e\u0433\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438.<\/p>\n<p><em><sup>1 <\/sup>\u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 Python 3.9, \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0435 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432. \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u043c\u0435\u0441\u0442\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440,\u00a0<\/em><code>typing.Dict[x, y]<\/code><em>\u00a0\u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u00a0<\/em><code>dict[x,y]<\/code><sup> <\/sup><\/p>\n<p><em><sup>2<\/sup> \u042d\u0442\u043e\u0442 \u043c\u043e\u0434\u0443\u043b\u044c \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043e\u043a \u0442\u0438\u043f\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u043d\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c\\\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0438\u043b\u0438 \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441\u043e\u0432.<\/em><\/p>\n<details class=\"spoiler\">\n<summary>\u0418\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/summary>\n<div class=\"spoiler__content\">\n<p><sup> <\/sup><a href=\"https:\/\/docs.python.org\/3.9\/library\/typing.html\" rel=\"noopener noreferrer nofollow\"><em>\u042d\u0442\u043e\u0442 \u043c\u043e\u0434\u0443\u043b\u044c<\/em><\/a><em> \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043e\u043a \u0442\u0438\u043f\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u041d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0444\u0443\u043d\u0434\u0430\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0442\u0438\u043f\u043e\u0432 Any, Union, Callable, TypeVar \u0438 Generic. \u041f\u043e\u043b\u043d\u0443\u044e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e \u0441\u043c. \u0432 PEP 484.<\/em>  <\/p>\n<p><em>\u041d\u043e, <\/em><a href=\"https:\/\/peps.python.org\/pep-0484\/#non-goals\" rel=\"noopener noreferrer nofollow\"><em>PEP 484 \u2013 Type Hints<\/em><\/a> <em>\u0425\u043e\u0442\u044f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u043c\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u0438\u043f\u043e\u0432 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f &#8212; \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0444\u0443\u043d\u043a\u0446\u0438\u044e get_type_hints() &#8212; \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u0438\u043f\u043e\u0432 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c\\\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0438\u043b\u0438 \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441\u043e\u0432. \u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0434\u0447\u0435\u0440\u043a\u043d\u0443\u0442\u044c, \u0447\u0442\u043e Python \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u044f\u0437\u044b\u043a\u043e\u043c, \u0438 \u0443 \u0430\u0432\u0442\u043e\u0440\u043e\u0432 \u043d\u0435\u0442 \u0436\u0435\u043b\u0430\u043d\u0438\u044f \u043a\u043e\u0433\u0434\u0430-\u043b\u0438\u0431\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438 \u0442\u0438\u043f\u043e\u0432 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438, \u0434\u0430\u0436\u0435 \u043f\u043e \u0441\u043e\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u044e.<\/em><\/p>\n<\/div>\n<\/details>\n<p>\u041e\u0434\u0438\u043d \u0438\u0437 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 &#8212; \u044d\u0442\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430. \u041d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432\u0432\u043e\u0434\u0438\u043c\u044b\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0430\u0434\u0440\u0435\u0441 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u0435\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 xxx@xx.com, \u0432\u043e\u0437\u0440\u0430\u0441\u0442 \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c, \u0444\u0430\u043c\u0438\u043b\u0438\u044f \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0442\u044c 20 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0438 \u0442.\u0434.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0447\u0443 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c 7 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 Python \u0438\u043b\u0438 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a. \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u043a\u0430\u043a\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0432\u044b \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u0435\u0442\u0435?  \u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b, \u043f\u0438\u0448\u0438\u0442\u0435 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445. <em>\u041f\u043e\u0435\u0445\u0430\u043b\u0438.<\/em><\/p>\n<h3>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 1: \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440\u0430<\/h3>\n<p>\u041c\u044b \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0441\u0430\u043c\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f: \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430. \u0417\u0434\u0435\u0441\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c 3 \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0438\u043c\u0435\u043d\u0438, \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b \u0438 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430 \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u0410\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u0440\u0438 \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435 \u0441\u0440\u0430\u0437\u0443 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 ValueError \u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f.<\/p>\n<details class=\"spoiler\">\n<summary>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 1<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import re  class Citizen:     def __init__(self, id, name, email, age):         self.id = id         self.name = self._is_valid_name(name)         self.email = self._is_valid_email(email)         self.age = self._is_valid_age(age)      def _is_valid_name(self, name):         if len(name) > 20:             raise ValueError(\"Name cannot exceed 20 characters.\")         return name      def _is_valid_email(self, email):         regex = \"^[a-z0-9]+[\\._]?[a-z0-9]+[@]\\w+[.]\\w{2,3}$\"         if not re.match(regex, email):             raise ValueError(\"It's not an email address.\")         return email      def _is_valid_age(self, age):         if age &lt; 0:             raise ValueError(\"Age cannot be negative.\")         return age  xiaoxu = Citizen(\"id1\", \"xiaoxu gao\", \"xiaoxugao@gmail.com\", 27) xiaoxu = Citizen(\"id1\", \"xiaoxu1234567890123456789\", \"xiaoxugao@gmail.com\", 27) # ValueError: Name cannot exceed 20 characters. xiaoxu = Citizen(\"id1\", \"xiaoxu gao\", \"xiaoxugao@gmail.c\", 27) # ValueError: It's not an email address. xiaoxu = Citizen(\"id1\", \"xiaoxu gao\", \"xiaoxugao@gmail.com\", -27) # ValueError: Age cannot be negative.<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u042d\u0442\u043e\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043f\u0440\u043e\u0441\u0442, \u043d\u043e, \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u044d\u0442\u043e, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u043d\u0435 \u0441\u0430\u043c\u043e\u0435 &#171;Pythonic&#187; \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u044b \u043a\u043e\u0433\u0434\u0430-\u043b\u0438\u0431\u043e \u0432\u0438\u0434\u0435\u043b\u0438, \u0430 \u043c\u043d\u043e\u0433\u0438\u0435 \u043b\u044e\u0434\u0438 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u044e\u0442 \u0438\u043c\u0435\u0442\u044c \u0447\u0438\u0441\u0442\u044b\u0439 <code>__init__<\/code>, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e. \u0414\u0440\u0443\u0433\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0443 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u043e \u043d\u0435\u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0431\u0435\u0437 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0442\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"python\">xiaoxu = Citizen(\"id1\", \"xiaoxu gao\", \"highsmallxu@gmail.com\", 27) xiaoxu.email = \"xiaoxugao@gmail.c\"  # This email is not valid, but still accepted by the code<\/code><\/pre>\n<h2>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 1\/2: __setattr__<\/h2>\n<p><em>\u0414\u043e\u0431\u0430\u0432\u0438\u043b \u043e\u0442 \u0441\u0435\u0431\u044f \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u0432\u0430\u0440\u0438\u0430\u043d\u0442. \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 magi\u0441 \u043c\u0435\u0442\u043e\u0434\u0435 __setattr__, \u0447\u0442\u043e \u0440\u0435\u0448\u0430\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430:<\/em><\/p>\n<details class=\"spoiler\">\n<summary>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 1\/2<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import re  class Citizen:     def __init__(self, id, name, email, age):         self.id = id         self.name = name         self.email = email         self.age = age      def _is_valid_name(self, name):         return len(name) &lt; 20      def _is_valid_email(self, email):         regex = \"^[a-z0-9]+[\\._]?[a-z0-9]+[@]\\w+[.]\\w{2,3}$\"         return re.match(regex, email)      def _is_valid_age(self, age):         return age > 0      def __setattr__(self, key, value):         if key == 'name' and not self._is_valid_name(value):             raise ValueError(\"Name cannot exceed 20 characters.\")         if key == 'email' and not self._is_valid_email(value):             raise ValueError(\"It's not an email address.\")         if key == 'age' and not self._is_valid_age(value):             raise ValueError(\"Age cannot be negative.\")         super().__setattr__(key, value)   xiaoxu = Citizen(\"id1\", \"xiaoxu gao\", \"xiaoxugao@gmail.com\", 27) xiaoxu = Citizen(\"id1\", \"xiaoxu1234567890123456789\", \"xiaoxugao@gmail.com\", 27) # ValueError: Name cannot exceed 20 characters. xiaoxu = Citizen(\"id1\", \"xiaoxu gao\", \"xiaoxugao@gmail.c\", 27) # ValueError: It's not an email address. xiaoxu = Citizen(\"id1\", \"xiaoxu gao\", \"xiaoxugao@gmail.com\", -27) # ValueError: Age cannot be negative.<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h3>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 2: \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 @property<\/h3>\n<p>\u0412\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f: <code>@property<\/code>. \u041e\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u043a \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0443. \u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Python:<\/p>\n<blockquote>\n<p>\u041e\u0431\u044a\u0435\u043a\u0442 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438\u043c\u0435\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u044b getter, setter \u0438 deleter, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0437\u0434\u0430\u044e\u0442 \u043a\u043e\u043f\u0438\u044e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u0434\u043e\u0441\u0442\u0443\u043f\u0430, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u043d\u0430 \u0434\u0435\u043a\u043e\u0440\u0438\u0440\u0443\u0435\u043c\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e.<\/p>\n<\/blockquote>\n<p>\u041d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u043e\u043d \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u043a\u043e\u0434\u0430, \u0447\u0435\u043c \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u043d\u043e \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0441\u043d\u0438\u043c\u0430\u0435\u0442 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0441 <code>__init__<\/code>. \u041a\u0430\u0436\u0434\u044b\u0439 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u0438\u043c\u0435\u0435\u0442 2 \u043c\u0435\u0442\u043e\u0434\u0430 (\u043a\u0440\u043e\u043c\u0435 id), \u043e\u0434\u0438\u043d \u0441 <code>@property<\/code>, \u0434\u0440\u0443\u0433\u043e\u0439 \u0441 setter. \u041f\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 citizen.name, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 \u0441 <code>@property.<\/code> \u041a\u043e\u0433\u0434\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u043b\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 citizen.name=&#187;xiaoxu&#187;, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 \u0441 setter.<\/p>\n<details class=\"spoiler\">\n<summary>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 2<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import re  class Citizen:     def __init__(self, id, name, email, age):         self._id = id         self.name = name         self.email = email         self.age = age      @property     def id(self):         return self._id      @property     def name(self):         return self._name      @name.setter     def name(self, value):         if len(value) > 20:             raise ValueError(\"Name cannot exceed 20 characters.\")         self._name = value      @property     def email(self):         return self._email      @email.setter     def email(self, value):         regex = \"^[a-z0-9]+[\\._]?[a-z0-9]+[@]\\w+[.]\\w{2,3}$\"         if not re.match(regex, value):             raise ValueError(\"It's not an email address.\")         self._email = value      @property     def age(self):         return self._age      @age.setter     def age(self, value):         if value &lt; 0:             raise ValueError(\"Age cannot be negative.\")         self._age = value  xiaoxu = Citizen(\"id1\", \"xiaoxu gao\", \"xiaoxu.gao@ing.com\", 27) xiaoxu = Citizen(\"id1\", \"xiaoxu1234567890123456789\", \"highsmallxu@gmail.com\", 27) # ValueError: Name cannot exceed 20 characters. xiaoxu = Citizen(\"id1\", \"xiaoxu gao\", \"highsmallxu@gmail.c\", 27) # ValueError: It's not an email address. xiaoxu = Citizen(\"id1\", \"xiaoxu gao\", \"highsmallxu@gmail.com\", -27) # ValueError: Age cannot be negative.<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u042d\u0442\u043e\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u0442 \u043b\u043e\u0433\u0438\u043a\u0443 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0432 \u043c\u0435\u0442\u043e\u0434 setter \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u0438, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 <strong>init<\/strong> \u0447\u0438\u0441\u0442\u044b\u043c. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043a \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044e \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u043f\u043e\u0441\u043b\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u044d\u0442\u043e\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f:<\/p>\n<pre><code class=\"python\">xiaoxu = Citizen(\"id1\", \"xiaoxu gao\", \"highsmallxu@gmail.com\", 27) xiaoxu.email = \"xiaoxugao@gmail.c\"  # ValueError: It's not an email address.<\/code><\/pre>\n<p>\u0410\u0442\u0440\u0438\u0431\u0443\u0442 id \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0443 \u043d\u0435\u0433\u043e \u043d\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u0430 setter. \u042d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u044f \u0445\u043e\u0447\u0443 \u0441\u043e\u043e\u0431\u0449\u0438\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0443, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u0442\u0435\u0441\u044c \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 AttributeError.<\/p>\n<h3>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 3: \u0414\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b<\/h3>\n<p>\u0422\u0440\u0435\u0442\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <a href=\"https:\/\/docs.python.org\/3\/howto\/descriptor.html#descriptor-howto-guide\" rel=\"noopener noreferrer nofollow\">\u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b<\/a> Python, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043c\u043e\u0449\u043d\u043e\u0439, \u043d\u043e \u0447\u0430\u0441\u0442\u043e \u0443\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u043e\u0439 \u0438\u0437 \u0432\u0438\u0434\u0443 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e \u043e\u0441\u043e\u0437\u043d\u0430\u043b\u043e \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443: \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 Python 3.9 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u0431\u044b\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b <a href=\"https:\/\/docs.python.org\/3\/howto\/descriptor.html#validator-class\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u043e\u0432 <\/a>\u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432. <\/p>\n<p>\u0414\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 &#8212; \u044d\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434\u044b <code>__get__(),<\/code> <code>__set__()<\/code> \u0438\u043b\u0438 <code>__delete__()<\/code>. \u041e\u043d \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043f\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432.<\/p>\n<p>\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0439 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b. \u041a\u0430\u0436\u0434\u044b\u0439 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 \u0441 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 <code>__get__<\/code> \u0438 <code>__set__<\/code>. \u041a\u043e\u0433\u0434\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 self.name=name, \u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>__set__<\/code>. \u041a\u043e\u0433\u0434\u0430 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442\u0441\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 print(self.name), \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>__get__<\/code>.<\/p>\n<details class=\"spoiler\">\n<summary>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 3.1<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import re  class Name:     def __get__(self, obj, objtype=None):         return self.value      def __set__(self, obj, value):         if len(value) > 20:             raise ValueError(\"Name cannot exceed 20 characters.\")         self.value = value  class Email:     def __get__(self, obj, objtype=None):         return self.value      def __set__(self, obj, value):         regex = \"^[a-z0-9]+[\\._]?[a-z0-9]+[@]\\w+[.]\\w{2,3}$\"         if not re.match(regex, value):             raise ValueError(\"It's not an email address.\")         self.value = value  class Age:     def __get__(self, obj, objtype=None):         return self.value      def __set__(self, obj, value):         if value &lt; 0:             raise ValueError(\"Age cannot be negative.\")         self.value = value  class Citizen:      name = Name()     email = Email()     age = Age()      def __init__(self, id, name, email, age):         self.id = id         self.name = name         self.email = email         self.age = age  xiaoxu = Citizen(\"id1\", \"xiaoxu gao\", \"xiaoxugao@gmail.com\", 27) xiaoxu = Citizen(\"id1\", \"xiaoxu1234567890123456789\", \"highsmallxu@gmail.com\", 27) # ValueError: Name cannot exceed 20 characters. xiaoxu = Citizen(\"id1\", \"xiaoxu gao\", \"highsmallxu@gmail.c\", 27) # ValueError: It's not an email address. xiaoxu = Citizen(\"id1\", \"xiaoxu gao\", \"highsmallxu@gmail.com\", -27) # ValueError: Age cannot be negative.<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u042d\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0441\u0440\u0430\u0432\u043d\u0438\u043c\u043e \u0441 <code>@property<\/code>. \u041e\u043d\u043e \u043b\u0443\u0447\u0448\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043a\u043e\u0433\u0434\u0430 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u0430\u0445. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 Employee \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b \u0431\u0435\u0437 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043a\u043e\u0434\u0430:<\/p>\n<details class=\"spoiler\">\n<summary>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 3.2<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">class Salary:     def __get__(self, obj):         self.value      def __set__(self, obj, value):         if value &lt; 1000:             raise ValueError(\"Salary cannot be lower than 1000.\")         self.value = value          class Employee:     name = Name()     email = Email()     age = Age()     salary = Salary()      def __init__(self, id, name, email, age, salary):         self.id = id         self.name = name         self.email = email         self.age = age         self.salary = salary          xiaoxu = Employee(\"id1\", \"xiaoxu gao\", \"xiaoxugao@gmail.com\", 27, 1000) xiaoxu = Employee(\"id1\", \"xiaoxu gao\", \"xiaoxugao@gmail.com\", 27, 999) # ValueError: Salary cannot be lower than 1000.<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h2>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 4: \u0421\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0435 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0438 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u043e\u0432<\/h2>\n<p>\u0420\u0430\u0437\u0432\u0438\u0442\u0438\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 3 &#8212; \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b \u0438 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b. \u041a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0433\u0434\u0435 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b \u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c\u0438 \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430\u0445:<\/p>\n<details class=\"spoiler\">\n<summary>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 4<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\"># \u0414\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b \u0438\u0437 \u0412\u0430\u0440\u0438\u0430\u043d\u0442\u0430 3 class Name:     def __get__(self, obj, objtype=None):         return self.value      def __set__(self, obj, value):         if len(value) > 20:             raise ValueError(\"Name cannot exceed 20 characters.\")         self.value = value  class Email:     def __get__(self, obj, objtype=None):         return self.value      def __set__(self, obj, value):         regex = \"^[a-z0-9]+[\\._]?[a-z0-9]+[@]\\w+[.]\\w{2,3}$\"         if not re.match(regex, value):             raise ValueError(\"It's not an email address.\")         self.value = value  class Age:     def __get__(self, obj, objtype=None):         return self.value      def __set__(self, obj, value):         if value &lt; 0:             raise ValueError(\"Age cannot be negative.\")         self.value = value  # \u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b-\u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b def email(attr):     def decorator(cls):         setattr(cls, attr, Email())         return cls     return decorator  def age(attr):     def decorator(cls):         setattr(cls, attr, Age())         return cls     return decorator  def name(attr):     def decorator(cls):         setattr(cls, attr, Name())         return cls     return decorator  @email(\"email\") @age(\"age\") @name(\"name\") class Citizen:     def __init__(self, id, name, email, age):         self.id = id         self.name = name         self.email = email         self.age = age<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u042d\u0442\u0438 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043b\u0435\u0433\u043a\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u044b. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u043c\u0435\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043e\u0431\u0449\u0438\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0441 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <code>@positive_number(attr1,attr2)<\/code><\/p>\n<h2>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 5: \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 __post_init__  \u0432 @dataclass<\/h2>\n<p>\u0414\u0440\u0443\u0433\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u0432 Python \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>@dataclass<\/code>. <a href=\"https:\/\/docs.python.org\/3\/library\/dataclasses.html\" rel=\"noopener noreferrer nofollow\">Dataclass<\/a> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430<code>__init__()<\/code>.<\/p>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e,  <code>@dataclass<\/code> \u0442\u0430\u043a\u0436\u0435 \u0432\u0432\u043e\u0434\u0438\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <code>__post_init__()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u0437 \u0441\u043a\u0440\u044b\u0442\u043e\u0433\u043e <code>__init__(). __post_init__<\/code> &#8212;  \u044d\u0442\u043e \u043c\u0435\u0441\u0442\u043e \u0434\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u043e\u043b\u0435\u0439 \u0438\u043b\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u0430\u0432\u0438\u043b \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438.<\/p>\n<details class=\"spoiler\">\n<summary>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 5<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">from dataclasses import dataclass import re  @dataclass class Citizen:      id: str     name: str     email: str     age: int      def __post_init__(self):         if self.age &lt; 0:             raise ValueError(\"Age cannot be negative.\")         regex = \"^[a-z0-9]+[\\._]?[a-z0-9]+[@]\\w+[.]\\w{2,3}$\"         if not re.match(regex, self.email):             raise ValueError(\"It's not an email address.\")         if len(self.name) > 20:             raise ValueError(\"Name cannot exceed 20 characters.\")  xiaoxu = Citizen(\"id1\", \"xiaoxu gao\", \"xiaoxu.gao@ing.com\", 27) xiaoxu = Citizen(\"id1\", \"xiaoxu1234567890123456789\", \"highsmallxu@gmail.com\", 27) # ValueError: Name cannot exceed 20 characters. xiaoxu = Citizen(\"id1\", \"xiaoxu gao\", \"highsmallxu@gmail.c\", 27) # ValueError: It's not an email address. xiaoxu = Citizen(\"id1\", \"xiaoxu gao\", \"highsmallxu@gmail.com\", -27) # ValueError: Age cannot be negative.<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u042d\u0442\u043e\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0438\u043c\u0435\u0435\u0442 \u0442\u043e\u0442 \u0436\u0435 \u044d\u0444\u0444\u0435\u043a\u0442, \u0447\u0442\u043e \u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 1, \u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u0442\u0438\u043b\u044c <code>@dataclass<\/code>. <\/p>\n<p>\u0414\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 5 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 Python \u0443\u0436\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043c\u043e\u0449\u043d\u044b\u0435, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043a\u0440\u044b\u0442\u044c \u0442\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u0447\u0430\u0441\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0442\u0430\u043a\u0436\u0435 \u043e\u0433\u043b\u044f\u043d\u0435\u043c\u0441\u044f \u0432\u043e\u043a\u0440\u0443\u0433 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438.<\/p>\n<h2>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 6: marshmallow<\/h2>\n<p><a href=\"https:\/\/marshmallow.readthedocs.io\/en\/stable\/index.html\" rel=\"noopener noreferrer nofollow\">Marshmallow<\/a> &#8212; \u044d\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 Python \u0434\u043b\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0440\u043e\u0434\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445 Python \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e. \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0438 \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u0445\u0435\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430. \u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u0449\u0435\u0439, \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u0434\u0435\u043b\u0430\u044e\u0442 \u044d\u0442\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043c\u043e\u0449\u043d\u043e\u0439:<\/p>\n<ul>\n<li>\n<p>\u041f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438, \u0442\u0430\u043a\u0438\u0445, \u043a\u0430\u043a Length, Date, Range, Email \u0438 \u0442.\u0434., \u0447\u0442\u043e \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c \u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438 \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u0443\u044e \u0441\u0445\u0435\u043c\u0443.<\/p>\n<\/li>\n<li>\n<p>ValidationError \u0438\u0437 Marshmallow \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u0441\u0435 \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u044b\u0435 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u043b\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0432\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438. \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0432\u0441\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0437\u0430 \u043e\u0434\u0438\u043d \u0440\u0430\u0437.<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 birthday \u0438 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u0430\u044f \u0441\u0445\u0435\u043c\u0430 HomeAddressSchema, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0430\u043c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438.<\/p>\n<details class=\"spoiler\">\n<summary>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 6<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">from marshmallow import Schema, fields, validate, ValidationError  class HomeAddressSchema(Schema):     postcode = fields.Str(validate=validate.Regexp(\"^\\d{4}\\s?\\w{2}$\"))     city = fields.Str()     country = fields.Str()  class CitizenSchema(Schema):     id = fields.Str()     name = fields.Str(validate=validate.Length(max=20))     birthday = fields.Date()     email = fields.Email()     age = fields.Integer(validate=validate.Range(min=1))     address = fields.Nested(HomeAddressSchema())<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041f\u043e\u0432\u0435\u0440\u0445 \u0441\u0445\u0435\u043c\u044b \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 Citizen. \u042f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e <code>@dataclass<\/code>, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u043e\u0434\u044b <code>__init__<\/code>. Marshmallow \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 JSON \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f asdict().<\/p>\n<details class=\"spoiler\">\n<summary>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 6 (\u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435)<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">from dataclasses import dataclass, asdict  @dataclass class Citizen:     id: str     name: str     birthday: str     email: str     age: int     address: object  citizen = Citizen(     id=\"1234\",     name=\"xiaoxugao\",     birthday=\"1990-01-01\",     email=\"xiaoxugao@gmail.com\",     age=1,     address={\"postcode\": \"1095AB\", \"city\": \"Amsterdam\", \"country\": \"NL\"}, )  CitizenSchema().load(asdict(citizen))  citizen.name = \"xiaoxugao1231234567890-1234567890\" citizen.email = \"xiaoxugao@gmail.c\" CitizenSchema().load(asdict(citizen)) # marshmallow.exceptions.ValidationError: {'email': ['Not a valid email address.'], 'name': ['Longer than maximum length 20.']}<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 &#171;\u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442&#187; \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0441 \u043d\u0435\u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u0441\u043b\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u0441\u0442\u0440\u043e\u043a\u0430\u0445 23 \u0438 24 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 citizen \u0441 \u043d\u0435\u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u043c\u0438 \u0438\u043c\u0435\u043d\u0435\u043c \u0438 email.<\/p>\n<p>\u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435\u0441\u044c \u043a <a href=\"https:\/\/marshmallow.readthedocs.io\/en\/stable\/quickstart.html#validation\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Marshmallow.<\/a><\/p>\n<h2>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 7: Pydantic<\/h2>\n<p><a href=\"https:\/\/pydantic-docs.helpmanual.io\/\" rel=\"noopener noreferrer nofollow\">Pydantic<\/a> &#8212; \u044d\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u043f\u043e\u0445\u043e\u0436\u0430\u044f \u043d\u0430 Marshmallow. \u041e\u043d\u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0434\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0445\u0435\u043c\u044b \u0438\u043b\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438, \u0442\u0430\u043a\u0438\u0445, \u043a\u0430\u043a PositiveInt, EmailStr \u0438 \u0442.\u0434. \u041f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 Marshmallow, Pydantic \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0432 \u043a\u043b\u0430\u0441\u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0430 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0441\u0445\u0435\u043c\u044b.<\/p>\n<p>\u0412\u043e\u0442 \u043a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0441\u0442\u0438\u0447\u044c \u0442\u043e\u0439 \u0436\u0435 \u0446\u0435\u043b\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Pydantic. ValidationError \u0445\u0440\u0430\u043d\u0438\u0442 \u0432\u0441\u0435 3 \u043e\u0448\u0438\u0431\u043a\u0438, \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0435 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0435.<\/p>\n<details class=\"spoiler\">\n<summary>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 7<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">from pydantic import BaseModel, ValidationError, validator, PositiveInt, EmailStr  class HomeAddress(BaseModel):     postcode: str     city: str     country: str      class Config:         anystr_strip_whitespace = True      @validator('postcode')     def dutch_postcode(cls, v):         if not re.match(\"^\\d{4}\\s?\\w{2}$\", v):             raise ValueError(\"must follow regex ^\\d{4}\\s?\\w{2}$\")         return v  class Citizen(BaseModel):     id: str     name: str     birthday: str     email: EmailStr     age: PositiveInt     address: HomeAddress      @validator('birthday')     def valid_date(cls, v):         try:             datetime.strptime(v, \"%Y-%m-%d\")             return v         except ValueError:             raise ValueError(\"date must be in YYYY-MM-DD format.\")  try:     citizen = Citizen(         id=\"1234\",         name=\"xiaoxugao1234567889901234567890\",         birthday=\"1990-01-32\",         email=\"xiaoxugao@gmail.\",         age=0,         address=HomeAddress(             postcode=\"1095AB\", city=\" Amsterdam\", country=\"NL\"         ),     )     print(citizen) except ValidationError as e:     print(e)      # 3 validation errors for Citizen # birthday #   date must be in YYYY-MM-DD format. (type=value_error) # email #   value is not a valid email address (type=value_error.email) # age #   ensure this value is greater than 0 (type=value_error.number.not_gt; limit_value=0)<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u042f \u043b\u0438\u0447\u043d\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u044e \u0438\u043c\u0435\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u043a\u043b\u0430\u0441\u0441 \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0438\u0437-\u0437\u0430 \u0435\u0433\u043e \u044f\u0441\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>\u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, Pydantic \u043c\u043e\u0436\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u044d\u0442\u043e. \u041e\u043d \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u0441\u0445\u0435\u043c\u044b \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0442\u043e\u0434 schema_json.<\/p>\n<pre><code>print(Citizen.schema_json(indent=2))<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>json<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"json\">{   \"title\": \"Citizen\",   \"type\": \"object\",   \"properties\": {     \"id\": {       \"title\": \"Id\",       \"type\": \"string\"     },     \"name\": {       \"title\": \"Name\",       \"type\": \"string\"     },     \"birthday\": {       \"title\": \"Birthday\",       \"type\": \"string\"     },     \"email\": {       \"title\": \"Email\",       \"type\": \"string\",       \"format\": \"email\"     },     \"age\": {       \"title\": \"Age\",       \"exclusiveMinimum\": 0,       \"type\": \"integer\"     },     \"address\": {       \"$ref\": \"#\/definitions\/HomeAddress\"     }   },   \"required\": [     \"id\",     \"name\",     \"birthday\",     \"email\",     \"age\",     \"address\"   ],   \"definitions\": {     \"HomeAddress\": {       \"title\": \"HomeAddress\",       \"type\": \"object\",       \"properties\": {         \"postcode\": {           \"title\": \"Postcode\",           \"type\": \"string\"         },         \"city\": {           \"title\": \"City\",           \"type\": \"string\"         },         \"country\": {           \"title\": \"Country\",           \"type\": \"string\"         }       },       \"required\": [         \"postcode\",         \"city\",         \"country\"       ]     }   } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0421\u0445\u0435\u043c\u0430 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u0430 \u0441 <a href=\"https:\/\/json-schema.org\/latest\/json-schema-core.html\" rel=\"noopener noreferrer nofollow\">JSON Schema Core<\/a>, <a href=\"https:\/\/json-schema.org\/latest\/json-schema-validation.html\" rel=\"noopener noreferrer nofollow\">JSON Schema Validation<\/a> \u0438 <a href=\"https:\/\/github.com\/OAI\/OpenAPI-Specification\" rel=\"noopener noreferrer nofollow\">OpenAPI<\/a>. \u041d\u043e, \u043a\u0430\u043a \u0438 \u0432 Marshmallow, \u044d\u0442\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0442\u0430\u043a\u0436\u0435 &#171;\u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442&#187; \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u0441 \u043d\u0435\u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u0441\u043b\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043b\u0430[<span class=\"habrahidden\">\u0430 \u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043b, \u0430\u0432\u0442\u043e\u0440 \u0441\u0442\u0430\u0442\u044c\u0438 &#8212; \u0434\u0435\u0432\u0443\u0448\u043a\u0430<\/span>] \u043e 7 \u043f\u043e\u0434\u0445\u043e\u0434\u0430\u0445 \u043a \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432. 5 \u0438\u0437 \u043d\u0438\u0445 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u044b \u043d\u0430 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445 Python, \u0430 2 &#8212; \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u0445.<\/p>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u0443\u044e \u0434\u0435\u0442\u0430\u043b\u044c \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438. \u041d\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443.<\/p>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0435\u0431\u044f \u043e\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0431\u0449\u0438\u0445 \u043f\u0440\u0430\u0432\u0438\u043b \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0435\u043d\u044c\u0448\u0435 \u043a\u043e\u0434\u0430. \u041d\u043e \u0432 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u043e\u043d\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u043d\u0430\u0442\u044c, \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043b\u0438 \u044d\u0442\u0438 \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0438\u0445 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f\u043c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0433\u0443\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043c\u043d\u0435\u043d\u0438\u044f \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0444\u043e\u0440\u043c\u0430\u0442 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0434\u043b\u044f Marshmallow, \u0442\u0430\u043a \u0438 \u0434\u043b\u044f Pydantic, \u043e\u043d\u0438 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0442 \u043d\u0435\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u043f\u0430\u0441\u043d\u043e \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445.<\/p>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0432\u0430\u043c \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u043b\u0430\u0441\u044c \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f. \u041f\u0438\u0448\u0438\u0442\u0435 \u0441\u0432\u043e\u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0438 \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u044f!<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/732388\/\"> https:\/\/habr.com\/ru\/articles\/732388\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0442\u0438\u043f\u043e\u0432 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 Python \u0433\u0438\u0431\u043a\u0438\u043c \u0438 \u043d\u0435\u044f\u0432\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c. \u0412 Python \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 Python 3 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u043c\u043e\u0434\u0443\u043b\u044c <sup>1<\/sup><a href=\"https:\/\/docs.python.org\/3.9\/library\/typing.html\" rel=\"noopener noreferrer nofollow\">typing<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043e\u043a \u0442\u0438\u043f\u043e\u0432 \u0432\u043e \u0432\u0440\u0435\u043c\u044f  <sup>2<\/sup>\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u041d\u043e \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0435\u0434\u0438\u043d\u043e\u0433\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438.<\/p>\n<p><em><sup>1 <\/sup>\u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 Python 3.9, \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0435 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432. \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u043c\u0435\u0441\u0442\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440,\u00a0<\/em><code>typing.Dict[x, y]<\/code><em>\u00a0\u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u00a0<\/em><code>dict[x,y]<\/code><sup> <\/sup><\/p>\n<p><em><sup>2<\/sup> \u042d\u0442\u043e\u0442 \u043c\u043e\u0434\u0443\u043b\u044c \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043e\u043a \u0442\u0438\u043f\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u043d\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c\\\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0438\u043b\u0438 \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441\u043e\u0432.<\/em><\/p>\n<details class=\"spoiler\">\n<summary>\u0418\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/summary>\n<div class=\"spoiler__content\">\n<p><sup> <\/sup><a href=\"https:\/\/docs.python.org\/3.9\/library\/typing.html\" rel=\"noopener noreferrer nofollow\"><em>\u042d\u0442\u043e\u0442 \u043c\u043e\u0434\u0443\u043b\u044c<\/em><\/a><em> \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043e\u043a \u0442\u0438\u043f\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u041d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0444\u0443\u043d\u0434\u0430\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0442\u0438\u043f\u043e\u0432 Any, Union, Callable, TypeVar \u0438 Generic. \u041f\u043e\u043b\u043d\u0443\u044e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e \u0441\u043c. \u0432 PEP 484.<\/em>  <\/p>\n<p><em>\u041d\u043e, <\/em><a href=\"https:\/\/peps.python.org\/pep-0484\/#non-goals\" rel=\"noopener noreferrer nofollow\"><em>PEP 484 \u2013 Type Hints<\/em><\/a> <em>\u0425\u043e\u0442\u044f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u043c\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u0438\u043f\u043e\u0432 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f &#8212; \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0444\u0443\u043d\u043a\u0446\u0438\u044e get_type_hints() &#8212; \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u0438\u043f\u043e\u0432 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c\\\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0438\u043b\u0438 \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441\u043e\u0432. \u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0434\u0447\u0435\u0440\u043a\u043d\u0443\u0442\u044c, \u0447\u0442\u043e Python \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u044f\u0437\u044b\u043a\u043e\u043c, \u0438 \u0443 \u0430\u0432\u0442\u043e\u0440\u043e\u0432 \u043d\u0435\u0442 \u0436\u0435\u043b\u0430\u043d\u0438\u044f \u043a\u043e\u0433\u0434\u0430-\u043b\u0438\u0431\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438 \u0442\u0438\u043f\u043e\u0432 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438, \u0434\u0430\u0436\u0435 \u043f\u043e \u0441\u043e\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u044e.<\/em><\/p>\n<\/div>\n<\/details>\n<p>\u041e\u0434\u0438\u043d \u0438\u0437 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 &#8212; \u044d\u0442\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430. \u041d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432\u0432\u043e\u0434\u0438\u043c\u044b\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0430\u0434\u0440\u0435\u0441 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u0435\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 xxx@xx.com, \u0432\u043e\u0437\u0440\u0430\u0441\u0442 \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c, \u0444\u0430\u043c\u0438\u043b\u0438\u044f \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0442\u044c 20 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0438 \u0442.\u0434.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0447\u0443 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c 7 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 Python \u0438\u043b\u0438 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a. \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u043a\u0430\u043a\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0432\u044b \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u0435\u0442\u0435?  \u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b, \u043f\u0438\u0448\u0438\u0442\u0435 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445. <em>\u041f\u043e\u0435\u0445\u0430\u043b\u0438.<\/em><\/p>\n<h3>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 1: \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440\u0430<\/h3>\n<p>\u041c\u044b \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0441\u0430\u043c\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f: \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430. \u0417\u0434\u0435\u0441\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c 3 \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0438\u043c\u0435\u043d\u0438, \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b \u0438 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430 \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u0410\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u0440\u0438 \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435 \u0441\u0440\u0430\u0437\u0443 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 ValueError \u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f.<\/p>\n<details class=\"spoiler\">\n<summary>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 1<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import re  class Citizen:     def __init__(self, id, name, email, age):         self.id = id         self.name = self._is_valid_name(name)         self.email = self._is_valid_email(email)         self.age = self._is_valid_age(age)      def _is_valid_name(self, name):         if len(name) > 20:             raise ValueError(\"Name cannot exceed 20 characters.\")         return name      def _is_valid_email(self, email):         regex = \"^[a-z0-9]+[\\._]?[a-z0-9]+[@]\\w+[.]\\w{2,3}$\"         if not re.match(regex, email):             raise ValueError(\"It's not an email address.\")         return email      def _is_valid_age(self, age):         if age &lt; 0:             raise ValueError(\"Age cannot be negative.\")         return age  xiaoxu = Citizen(\"id1\", \"xiaoxu gao\", \"xiaoxugao@gmail.com\", 27) xiaoxu = Citizen(\"id1\", \"xiaoxu1234567890123456789\", \"xiaoxugao@gmail.com\", 27) # ValueError: Name cannot exceed 20 characters. xiaoxu = Citizen(\"id1\", \"xiaoxu gao\", \"xiaoxugao@gmail.c\", 27) # ValueError: It's not an email address. xiaoxu = Citizen(\"id1\", \"xiaoxu gao\", \"xiaoxugao@gmail.com\", -27) # ValueError: Age cannot be negative.<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u042d\u0442\u043e\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043f\u0440\u043e\u0441\u0442, \u043d\u043e, \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u044d\u0442\u043e, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u043d\u0435 \u0441\u0430\u043c\u043e\u0435 &#171;Pythonic&#187; \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u044b \u043a\u043e\u0433\u0434\u0430-\u043b\u0438\u0431\u043e \u0432\u0438\u0434\u0435\u043b\u0438, \u0430 \u043c\u043d\u043e\u0433\u0438\u0435 \u043b\u044e\u0434\u0438 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u044e\u0442 \u0438\u043c\u0435\u0442\u044c \u0447\u0438\u0441\u0442\u044b\u0439 <code>__init__<\/code>, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e. \u0414\u0440\u0443\u0433\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0443 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u043e \u043d\u0435\u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0431\u0435\u0437 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0442\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"python\">xiaoxu = Citizen(\"id1\", \"xiaoxu gao\", \"highsmallxu@gmail.com\", 27) xiaoxu.email = \"xiaoxugao@gmail.c\"  # This email is not valid, but still accepted by the code<\/code><\/pre>\n<h2>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 1\/2: __setattr__<\/h2>\n<p><em>\u0414\u043e\u0431\u0430\u0432\u0438\u043b \u043e\u0442 \u0441\u0435\u0431\u044f \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u0432\u0430\u0440\u0438\u0430\u043d\u0442. \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 magi\u0441 \u043c\u0435\u0442\u043e\u0434\u0435 __setattr__, \u0447\u0442\u043e \u0440\u0435\u0448\u0430\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430:<\/em><\/p>\n<details class=\"spoiler\">\n<summary>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 1\/2<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import re  class Citizen:     def __init__(self, id, name, email, age):         self.id = id         self.name = name         self.email = email         self.age = age      def _is_valid_name(self, name):         return len(name) &lt; 20      def _is_valid_email(self, email):         regex = \"^[a-z0-9]+[\\._]?[a-z0-9]+[@]\\w+[.]\\w{2,3}$\"         return re.match(regex, email)      def _is_valid_age(self, age):         return age > 0      def __setattr__(self, key, value):         if key == 'name' and not self._is_valid_name(value):             raise ValueError(\"Name cannot exceed 20 characters.\")         if key == 'email' and not self._is_valid_email(value):             raise ValueError(\"It's not an email address.\")         if key == 'age' and not self._is_valid_age(value):             raise ValueError(\"Age cannot be negative.\")         super().__setattr__(key, value)   xiaoxu = Citizen(\"id1\", \"xiaoxu gao\", \"xiaoxugao@gmail.com\", 27) xiaoxu = Citizen(\"id1\", \"xiaoxu1234567890123456789\", \"xiaoxugao@gmail.com\", 27) # ValueError: Name cannot exceed 20 characters. xiaoxu = Citizen(\"id1\", \"xiaoxu gao\", \"xiaoxugao@gmail.c\", 27) # ValueError: It's not an email address. xiaoxu = Citizen(\"id1\", \"xiaoxu gao\", \"xiaoxugao@gmail.com\", -27) # ValueError: Age cannot be negative.<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h3>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 2: \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 @property<\/h3>\n<p>\u0412\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f: <code>@property<\/code>. \u041e\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u043a \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0443. \u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Python:<\/p>\n<blockquote>\n<p>\u041e\u0431\u044a\u0435\u043a\u0442 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438\u043c\u0435\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u044b getter, setter \u0438 deleter, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0437\u0434\u0430\u044e\u0442 \u043a\u043e\u043f\u0438\u044e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u0434\u043e\u0441\u0442\u0443\u043f\u0430, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u043d\u0430 \u0434\u0435\u043a\u043e\u0440\u0438\u0440\u0443\u0435\u043c\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e.<\/p>\n<\/blockquote>\n<p>\u041d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u043e\u043d \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u043a\u043e\u0434\u0430, \u0447\u0435\u043c \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u043d\u043e \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0441\u043d\u0438\u043c\u0430\u0435\u0442 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0441 <code>__init__<\/code>. \u041a\u0430\u0436\u0434\u044b\u0439 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u0438\u043c\u0435\u0435\u0442 2 \u043c\u0435\u0442\u043e\u0434\u0430 (\u043a\u0440\u043e\u043c\u0435 id), \u043e\u0434\u0438\u043d \u0441 <code>@property<\/code>, \u0434\u0440\u0443\u0433\u043e\u0439 \u0441 setter. \u041f\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 citizen.name, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 \u0441 <code>@property.<\/code> \u041a\u043e\u0433\u0434\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u043b\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 citizen.name=&#187;xiaoxu&#187;, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 \u0441 setter.<\/p>\n<details class=\"spoiler\">\n<summary>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 2<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import re  class Citizen:     def __init__(self, id, name, email, age):         self._id = id         self.name = name         self.email = email         self.age = age      @property     def id(self):         return self._id      @property     def name(self):         return self._name      @name.setter     def name(self, value):         if len(value) > 20:             raise ValueError(\"Name cannot exceed 20 characters.\")         self._name = value      @property     def email(self):         return self._email      @email.setter     def email(self, value):         regex = \"^[a-z0-9]+[\\._]?[a-z0-9]+[@]\\w+[.]\\w{2,3}$\"         if not re.match(regex, value):             raise ValueError(\"It's not an email address.\")         self._email = value      @property     def age(self):         return self._age      @age.setter     def age(self, value):         if value &lt; 0:             raise ValueError(\"Age cannot be negative.\")         self._age = value  xiaoxu = Citizen(\"id1\", \"xiaoxu gao\", \"xiaoxu.gao@ing.com\", 27) xiaoxu = Citizen(\"id1\", \"xiaoxu1234567890123456789\", \"highsmallxu@gmail.com\", 27) # ValueError: Name cannot exceed 20 characters. xiaoxu = Citizen(\"id1\", \"xiaoxu gao\", \"highsmallxu@gmail.c\", 27) # ValueError: It's not an email address. xiaoxu = Citizen(\"id1\", \"xiaoxu gao\", \"highsmallxu@gmail.com\", -27) # ValueError: Age cannot be negative.<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u042d\u0442\u043e\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u0442 \u043b\u043e\u0433\u0438\u043a\u0443 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0432 \u043c\u0435\u0442\u043e\u0434 setter \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u0438, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 <strong>init<\/strong> \u0447\u0438\u0441\u0442\u044b\u043c. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043a \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044e \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u043f\u043e\u0441\u043b\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u044d\u0442\u043e\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f:<\/p>\n<pre><code class=\"python\">xiaoxu = Citizen(\"id1\", \"xiaoxu gao\", \"highsmallxu@gmail.com\", 27) xiaoxu.email = \"xiaoxugao@gmail.c\"  # ValueError: It's not an email address.<\/code><\/pre>\n<p>\u0410\u0442\u0440\u0438\u0431\u0443\u0442 id \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0443 \u043d\u0435\u0433\u043e \u043d\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u0430 setter. \u042d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u044f \u0445\u043e\u0447\u0443 \u0441\u043e\u043e\u0431\u0449\u0438\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0443, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u0442\u0435\u0441\u044c \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 AttributeError.<\/p>\n<h3>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 3: \u0414\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b<\/h3>\n<p>\u0422\u0440\u0435\u0442\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <a href=\"https:\/\/docs.python.org\/3\/howto\/descriptor.html#descriptor-howto-guide\" rel=\"noopener noreferrer nofollow\">\u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b<\/a> Python, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043c\u043e\u0449\u043d\u043e\u0439, \u043d\u043e \u0447\u0430\u0441\u0442\u043e \u0443\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u043e\u0439 \u0438\u0437 \u0432\u0438\u0434\u0443 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e \u043e\u0441\u043e\u0437\u043d\u0430\u043b\u043e \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443: \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 Python 3.9 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u0431\u044b\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b <a href=\"https:\/\/docs.python.org\/3\/howto\/descriptor.html#validator-class\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u043e\u0432 <\/a>\u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432. <\/p>\n<p>\u0414\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 &#8212; \u044d\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434\u044b <code>__get__(),<\/code> <code>__set__()<\/code> \u0438\u043b\u0438 <code>__delete__()<\/code>. \u041e\u043d \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043f\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432.<\/p>\n<p>\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0439 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b. \u041a\u0430\u0436\u0434\u044b\u0439 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 \u0441 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 <code>__get__<\/code> \u0438 <code>__set__<\/code>. \u041a\u043e\u0433\u0434\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 self.name=name, \u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>__set__<\/code>. \u041a\u043e\u0433\u0434\u0430 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442\u0441\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 print(self.name), \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>__get__<\/code>.<\/p>\n<details class=\"spoiler\">\n<summary>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 3.1<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import re  class Name:     def __get__(self, obj, objtype=None):         return self.value      def __set__(self, obj, value):         if len(value) > 20:             raise ValueError(\"Name cannot exceed 20 characters.\")         self.value = value  class Email:     def __get__(self, obj, objtype=None):         return self.value      def __set__(self, obj, value):         regex = \"^[a-z0-9]+[\\._]?[a-z0-9]+[@]\\w+[.]\\w{2,3}$\"         if not re.match(regex, value):             raise ValueError(\"It's not an email address.\")         self.value = value  class Age:     def __get__(self, obj, objtype=None):         return self.value      def __set__(self, obj, value):         if value &lt; 0:             raise ValueError(\"Age cannot be negative.\")         self.value = value  class Citizen:      name = Name()     email = Email()     age = Age()      def __init__(self, id, name, email, age):         self.id = id         self.name = name<\/code><\/pre>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-387995","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/387995","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=387995"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/387995\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=387995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=387995"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=387995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}