{"id":375220,"date":"2024-05-21T06:19:07","date_gmt":"2024-05-21T06:19:07","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=375220"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=375220","title":{"rendered":"<span>Python \u2014 \u0414\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b (Descriptors)<\/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>\u0415\u0441\u043b\u0438 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u0442\u043e <strong>\u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440<\/strong> \u2014 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c <strong>\u043f\u043e\u0438\u0441\u043a<\/strong>, <strong>\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435<\/strong> \u0438 <strong>\u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435<\/strong> \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432.<\/p>\n<p>\u0414\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u043a\u043b\u0430\u0441\u0441\u0430\u0445, \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u044f \u0432 \u0440\u043e\u043b\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430(\u043d\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430). <\/p>\n<p>\u0414\u0443\u043c\u0430\u044e, \u043c\u0430\u043b\u043e \u043a\u0442\u043e, \u0445\u043e\u0442\u044f \u0431\u044b \u0440\u0430\u0437, \u0441\u0430\u043c \u043f\u0438\u0441\u0430\u043b \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b \u0432 \u043a\u043e\u043c\u043c\u0435\u0440\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435, \u043d\u043e \u044f \u0443\u0432\u0435\u0440\u0435\u043d, \u0447\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u0430\u043c\u0438, \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0438\u0445 &#171;\u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c&#187;:<\/p>\n<ul>\n<li>\n<p><code>classmethod<\/code>, <code>staticmethod<\/code><\/p>\n<\/li>\n<li>\n<p><code>property<\/code><\/p>\n<\/li>\n<li>\n<p><code>__slots__<\/code> <\/p>\n<\/li>\n<li>\n<p>\u0412 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435, \u043b\u044e\u0431\u043e\u0435 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0443 \u043a\u043b\u0430\u0441\u0441\u0430, \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u0430\u043c\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043d\u0438\u0445, \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0441 \u0432\u0430\u043c\u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0437\u0434\u043d\u0435\u0435.<\/p>\n<p>\u041f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u043e\u0432 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437:<\/p>\n<ul>\n<li>\n<p><code>__get__<\/code> &#8212; \u041f\u043e\u0438\u0441\u043a \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430<\/p>\n<\/li>\n<li>\n<p><code>__set__<\/code> &#8212; \u0425\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430<\/p>\n<\/li>\n<li>\n<p><code>__delete__<\/code>  &#8212; \u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u043f\u043e\u0438\u0441\u043a\u0430 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 &#8212; <code>__get__<\/code> . <\/p>\n<pre><code class=\"python\">class StaticValueDescriptor:     def __init__(self, value: Any) -> None:         self._value = value              def __get__(self, instance, owner=None) -> Any:         return self._value     class Object:     attr_1 = StaticValueDescriptor(100)       instance_object = Object() instance_object.attr_1  # -> 100<\/code><\/pre>\n<p>\u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0432 <strong>attr_1<\/strong> \u043c\u044b \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u043b\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <strong>StaticValueDescriptor<\/strong>, \u0432 \u043e\u0442\u0432\u0435\u0442\u0435 \u043c\u044b \u0432\u0438\u0434\u0438\u043c <strong>100<\/strong>, \u043d\u043e \u043f\u043e\u0447\u0435\u043c\u0443?<\/p>\n<p>\u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u0438 \u043f\u043e\u0438\u0441\u043a\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u043a\u043b\u0430\u0441\u0441\u0430(<strong>getattribute<\/strong>), <strong>python<\/strong> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c(<u>\u043f\u043e\u0434\u0447\u0435\u0440\u043a\u043d\u0443\u043b<\/u> \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u043a\u0443\u0441\u043a\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430):<\/p>\n<ul>\n<li>\n<p><strong>attr_1 <\/strong>\u0435\u0441\u0442\u044c \u0432 <code>__dict__<\/code> \u043a\u043b\u0430\u0441\u0441\u0430?<\/p>\n<ul>\n<li>\n<p>\u0414\u0430. \u0415\u0441\u0442\u044c \u043b\u0438 \u0443 \u043d\u0435\u0433\u043e <code>__get__<\/code> \u0438 (<code>__set__<\/code> \u0438\u043b\u0438 <code>__delete__<\/code>)(data descriptor)?<\/p>\n<ul>\n<li>\n<p>\u0414\u0430. \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440.<\/p>\n<\/li>\n<li>\n<p><u>\u041d\u0435\u0442. <\/u><strong><u>attr_1 <\/u><\/strong><u>\u0435\u0441\u0442\u044c \u0432 <\/u><code>__dict__<\/code><u> \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430?<\/u><\/p>\n<ul>\n<li>\n<p><u>\u0414\u0430. \u0412\u0435\u0440\u043d\u0443\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438\u0437 <\/u><code>__dict__<\/code><u> \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430.<\/u><\/p>\n<\/li>\n<li>\n<p><u>\u041d\u0435\u0442. <\/u><strong><u>attr_1 <\/u><\/strong><u>\u0435\u0441\u0442\u044c \u0432 <\/u><code>__dict__<\/code><u> \u043a\u043b\u0430\u0441\u0441\u0430?<\/u><\/p>\n<ul>\n<li>\n<p><u>\u0414\u0430. \u0415\u0441\u0442\u044c \u043b\u0438 \u0443 \u043d\u0435\u0433\u043e <\/u><code>__get__<\/code><u> (non-data descriptor)?<\/u><\/p>\n<ul>\n<li>\n<p><u>\u0414\u0430. \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440.<\/u><\/p>\n<\/li>\n<li>\n<p><u>\u041d\u0435\u0442. \u0412\u0435\u0440\u043d\u0443\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438\u0437 <\/u><code>__dict__<\/code><u> \u043a\u043b\u0430\u0441\u0441\u0430.<\/u><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><u>\u041d\u0435\u0442. \u0412\u044b\u0437\u043e\u0432 \u0443 \u043a\u043b\u0430\u0441\u0441\u0430 <\/u><code>getattr<\/code><u> , \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432\u043e\u0437\u0431\u0443\u0434\u0438\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 <\/u><strong><u>AttributeError.<\/u><\/strong><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><u>\u041d\u0435\u0442. <\/u><strong><u>attr_1 <\/u><\/strong><u>\u0435\u0441\u0442\u044c \u0432 <\/u><code>__dict__<\/code><u> \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430?<\/u><\/p>\n<ul>\n<li>\n<p><u>\u0414\u0430. \u0412\u0435\u0440\u043d\u0443\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438\u0437 <\/u><code>__dict__<\/code><u> \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430.<\/u><\/p>\n<\/li>\n<li>\n<p><u>\u041d\u0435\u0442. <\/u><strong><u>attr_1 <\/u><\/strong><u>\u0435\u0441\u0442\u044c \u0432 <\/u><code>__dict__<\/code><u> \u043a\u043b\u0430\u0441\u0441\u0430?<\/u><\/p>\n<ul>\n<li>\n<p><u>\u0414\u0430. \u0415\u0441\u0442\u044c \u043b\u0438 \u0443 \u043d\u0435\u0433\u043e <\/u><code>__get__<\/code><u> (non-data descriptor)?<\/u><\/p>\n<ul>\n<li>\n<p><u>\u0414\u0430. \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440.<\/u><\/p>\n<\/li>\n<li>\n<p><u>\u041d\u0435\u0442. \u0412\u0435\u0440\u043d\u0443\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438\u0437 <\/u><code>__dict__<\/code><u> \u043a\u043b\u0430\u0441\u0441\u0430.<\/u><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><u>\u041d\u0435\u0442. \u0412\u044b\u0437\u043e\u0432 \u0443 \u043a\u043b\u0430\u0441\u0441\u0430 <\/u><code>getattr<\/code><u> , \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432\u043e\u0437\u0431\u0443\u0434\u0438\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 <\/u><strong><u>AttributeError.<\/u><\/strong><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u0421\u043e\u0433\u043b\u0430\u0441\u0435\u043d, \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c, \u0442\u0430\u043a\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043f\u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u043c. \u042f \u0443\u043f\u0440\u043e\u0449\u0443 \u0435\u0433\u043e \u0438 \u043f\u043e\u043a\u0430\u0436\u0443 \u043b\u0438\u0448\u044c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u044b \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u043f\u0440\u0438 \u043f\u043e\u0438\u0441\u043a\u0435:<\/p>\n<ol>\n<li>\n<p><strong>Data descriptor<\/strong> &#8212; \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0435\u0441\u0442\u044c <code>__get__<\/code> \u0438 (<code>__set__<\/code> \u0438\u043b\u0438 <code>__delete__<\/code>)<\/p>\n<\/li>\n<li>\n<p><code>Instance.__dict__<\/code> <\/p>\n<\/li>\n<li>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0434\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0438\u043c\u0435\u044e\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442.<\/p>\n<ol>\n<li>\n<p><strong>Non-data descriptor<\/strong> &#8212; \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e <code>__get__<\/code> <\/p>\n<\/li>\n<li>\n<p><code>Class.__dict__<\/code><\/p>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>\u041c\u044b \u0435\u0449\u0451 \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u0432 \u043d\u0430 \u0434\u0435\u043b\u0435, \u0430 \u043f\u043e\u043a\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0443 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u043e\u0432.<\/p>\n<p>\u0415\u0449\u0451 \u043d\u0435 \u0434\u043e\u0439\u0434\u044f \u0434\u043e <code>__set__<\/code> \u0438\u043b\u0438 <code>__delete__<\/code> \u0443 \u0432\u0430\u0441, \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441 &#8212; &#171;\u0430 \u043a\u0430\u043a \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 \u0441 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u043c? \u042f \u043d\u0435 \u0445\u043e\u0447\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0445\u0430\u0440\u0434\u043a\u043e\u0434\u043d\u044b\u0435 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b&#187;. \u0418 \u043f\u0440\u0430\u0432\u0434\u0430, \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e <strong>StaticValueDescriptor <\/strong>\u0438\u043c\u0435\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u0437\u043a\u0443\u044e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u043e\u0441\u0442\u044c.<\/p>\n<p>\u0420\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u0441 \u0445\u043e\u0434\u0443 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 <code>__init__<\/code>. \u0418 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0440\u0430\u0437\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c <code>__set__<\/code>:<\/p>\n<pre><code class=\"python\">class DataDescriptor:     def __init__(self, attr_name: str) -> None:         self._attr_name = attr_name          def __get__(self, instance, owner=None) -> Any:         return instance.__dict__[self._attr_name]      def __set__(self, instance, value: Any) -> None:         instance.__dict__[self._attr_name] = value           class Object:   attr_1 = DataDescriptor(\"attr_1\")     instance_object = Object() instance_object.attr_1 = 100 instance_object.attr_1  # -> 100<\/code><\/pre>\n<p>\u0412 \u0446\u0435\u043b\u043e\u043c \u043c\u044b \u0440\u0435\u0448\u0438\u043b\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u0438 \u0441\u043c\u043e\u0433\u043b\u0438 \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0438\u043c\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043a\u043b\u0430\u0441\u0441\u0430, \u0433\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <strong>\u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440<\/strong>, \u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0449\u0451 \u043b\u0443\u0447\u0448\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>__set_name__<\/code>:<\/p>\n<pre><code class=\"python\">class DataDescriptor:     def __set_name__(self, owner, attr_name: str) -> None:         self._attr_name = attr_name      def __get__(self, instance, owner=None) -> Any:         return instance.__dict__[self._attr_name]      def __set__(self, instance, value: Any) -> None:         instance.__dict__[self._attr_name] = value           class Object:     attr_1 = DataDescriptor()       instance_object = Object() instance_object.attr_1 = 100 instance_object.attr_1  # -> 100<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0442\u043e\u0434 <code>__set_name__<\/code> \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0441\u043d\u0430\u0440\u0443\u0436\u0438. \u0425\u043e\u0442\u044f \u0443\u0432\u0435\u0440\u0435\u043d, \u043d\u0430\u0439\u0434\u0443\u0442\u0441\u044f \u0442\u0435, \u043a\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u044d\u0442\u043e:<\/p>\n<pre><code class=\"python\">class DataDescriptor:     def __init__(self, attr_name: str) -> None:         self._attr_name = attr_name          def __get__(self, instance, owner=None) -> Any:         return instance.__dict__[self._attr_name]      def __set__(self, instance, value: Any) -> None:         instance.__dict__[self._attr_name] = value           class Object:     attr_1 = DataDescriptor(\"attr_999\")  # \u041d\u0435 \u043d\u0430\u0434\u043e \u0442\u0430\u043a ?      def __init__(self):         self.attr_1 = 123           instance_object = Object() instance_object.attr_999  # -> 123<\/code><\/pre>\n<p>\u041d\u0443 \u0438 \u043d\u0430\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a \u0443 \u043d\u0430\u0441 \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f <code>__delete__<\/code> :<\/p>\n<pre><code class=\"python\">class DataDescriptor:     def __set_name__(self, owner, attr_name: str) -> None:         self._attr_name = attr_name          def __get__(self, instance, owner=None) -> Any:         return instance.__dict__[self._attr_name]      def __set__(self, instance, value: Any) -> None:         instance.__dict__[self._attr_name] = value          def __delete__(self, instance) -> None:         del instance.__dict__[self._attr_name]           class Object:     attr_1 = DataDescriptor()       instance_object = Object() instance_object.attr_1 = 100 instance_object.attr_1  # -> 100 del instance_object.attr_1 instance_object.attr_1  # -> KeyError: 'attr_1'<\/code><\/pre>\n<p>\u041d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0441\u043c\u0443\u0449\u0430\u0435\u0442? \u0410 \u0447\u0442\u043e \u044d\u0442\u043e \u0437\u0430 <strong>KeyError<\/strong> \u043f\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u043a\u043b\u0430\u0441\u0441\u0430? \u041d\u0435\u043f\u043e\u0440\u044f\u0434\u043e\u043a!<\/p>\n<p>\u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 <code>__get__<\/code> , \u043d\u0430\u0448\u0430 \u043f\u043e\u043f\u044b\u0442\u043a\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438\u0437 <code>instance.__dict__<\/code>  \u0442\u0435\u0440\u043f\u0438\u0442 \u043d\u0435\u0443\u0434\u0430\u0447\u0443, \u0442\u0430\u043a \u043a\u0430\u043a \u0442\u0430\u043a\u043e\u0433\u043e <strong>\u043a\u043b\u044e\u0447\u0430<\/strong> \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435 \u043d\u0435\u0442.<\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 <strong>KeyError<\/strong> \u0432 <code>__get__<\/code> , <code>__set__<\/code> , <code>__delete__<\/code> \u0438 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0443, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u043c\u0443 \u0432\u044b\u0448\u0435. \u041a\u0430\u0436\u0435\u0442\u0441\u044f, \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0440\u0443\u043a\u0430\u043c\u0438, \u043d\u0435\u043f\u0440\u0430\u0432\u0434\u0430 \u043b\u0438? \u0412\u044b\u0445\u043e\u0434 \u0435\u0441\u0442\u044c!<\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u0448\u0430\u0433 &#8212; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b(<strong>getattr<\/strong>, <strong>setattr<\/strong>, <strong>delattr<\/strong>), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0430\u0434\u0443\u0442 \u043d\u0430\u043c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"python\">class DataDescriptor:     def __set_name__(self, owner, attr_name: str) -> None:         self._attr_name = attr_name          def __get__(self, instance, owner=None) -> Any:         return getattr(instance, self._attr_name)      def __set__(self, instance, value: Any) -> None:         setattr(instance, self._attr_name, value)          def __delete__(self, instance) -> None:         delattr(instance, self._attr_name)           class Object:     attr_1 = DataDescriptor()       instance_object = Object() instance_object.attr_1 = 100 instance_object.attr_1  # -> 100 del instance_object.attr_1 instance_object.attr_1  # -> RecursionError: maximum recursion depth                         # exceeded while calling a Python object <\/code><\/pre>\n<p>\u041a\u0430\u0436\u0435\u0442\u0441\u044f, \u0443 \u043d\u0430\u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b? \u041f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a <strong>attr_1 <\/strong>\u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435<strong>:<\/strong><\/p>\n<ul>\n<li>\n<p>\u041c\u044b \u0432\u0441\u0451 \u043f\u043e \u0442\u043e\u043c\u0443 \u0436\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0443 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 \u0438 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u043c \u0432 <code>__get__<\/code> . <\/p>\n<\/li>\n<li>\n<p>\u0412\u043d\u0443\u0442\u0440\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>getattr(instance, self._attr_name, value)<\/code> <\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u0442\u043e\u0440\u044b\u0439, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u0437 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 <strong>attr_1<\/strong>(\u043f\u043e \u0441\u0443\u0442\u0438, \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0447\u0442\u043e \u043c\u044b \u043f\u044b\u0442\u0430\u043b\u0438\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e)<\/p>\n<\/li>\n<li>\n<p>\u0418 \u043c\u044b \u0441\u043d\u043e\u0432\u0430 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u043c \u0432 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 \u0438 \u0442\u0430\u043a \u043f\u043e \u043a\u0440\u0443\u0433\u0443.<\/p>\n<\/li>\n<\/ul>\n<p>\u0418 \u043d\u0430 \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0435\u0441\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435! <\/p>\n<p>\u0412\u0442\u043e\u0440\u043e\u0439 \u0448\u0430\u0433 &#8212; \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u0449\u0438\u0449\u0451\u043d\u043d\u044b\u0439(<strong>protected<\/strong>) \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0438\u043c\u0435\u043d\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430:<\/p>\n<pre><code class=\"python\">class DataDescriptor:     def __set_name__(self, owner, attr_name: str) -> None:         self._protected_attr_name = f\"_{attr_name}\"          def __get__(self, instance, owner=None) -> Any:         return getattr(instance, self._protected_attr_name)      def __set__(self, instance, value: Any) -> None:         setattr(instance, self._protected_attr_name, value)          def __delete__(self, instance) -> None:         delattr(instance, self._protected_attr_name)   class Object:     attr_1 = DataDescriptor()       instance_object = Object() instance_object.attr_1 = 100 instance_object.attr_1  # -> 100 del instance_object.attr_1 instance_object.attr_1  # -> AttributeError: 'Object' object has no attribute                         # '_attr_1'. Did you mean: 'attr_1'?<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0434\u043e\u0431\u0438\u043b\u0438\u0441\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438! <\/p>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u0432\u0430\u0441 \u0437\u0430\u0434\u0430\u0434\u0443\u0442\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c &#8212; &#171;\u041a\u0443\u0434\u0430 \u0434\u0435\u043b\u0430\u0441\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0435\u0439? \u041a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0432 \u043a\u043e\u0434\u0435 \u043d\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439.&#187;<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c, \u0447\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u043a <strong>attr_1<\/strong>:<\/p>\n<ul>\n<li>\n<p>\u041c\u044b \u0432\u0441\u0451 \u043f\u043e \u0442\u043e\u043c\u0443 \u0436\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0443 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 \u0438 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u043c \u0432 <code>__get__<\/code> .<\/p>\n<\/li>\n<li>\n<p>\u0412\u043d\u0443\u0442\u0440\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>getattr(instance, self._attr_name, value)<\/code><\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u0437 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0435 <strong>attr_1,<\/strong> \u0430 <strong>_attr_1<\/strong>. <strong>_attr_1<\/strong> \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u043e\u043c \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435 \u043f\u043e\u0432\u043b\u0435\u0447\u0451\u0442 \u0437\u0430 \u0441\u043e\u0431\u043e\u0439 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 <code>__get__<\/code> \u0438 \u0437\u0430\u0446\u0438\u043a\u043b\u0438\u0432\u0430\u043d\u0438\u0435, \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0449\u0435\u0435 \u043a \u043e\u0448\u0438\u0431\u043a\u0435(<strong>RecursionError<\/strong>)<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u0431\u0443\u0434\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0430\u0442\u0440\u0438\u0431\u0443\u0442 <code>_attr_1<\/code> , \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u043e\u043c:<\/p>\n<pre><code class=\"python\">instance_object = Object() instance_object.__dict__  # -> {} instance_object.attr_1 = 100 instance_object.__dict__  # -> {\"_attr_1\": 100}<\/code><\/pre>\n<p>\u0418 \u043d\u0430\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u043c\u0435\u0436\u0434\u0443 <strong>data<\/strong> \u0438 <strong>non-data<\/strong> \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u0430\u043c\u0438. \u041e\u043d\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u0430\u0445 \u043f\u043e\u0438\u0441\u043a\u0430 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430.<\/p>\n<p><strong>Data descriptor<\/strong> \u0438\u043c\u0435\u0435\u0442 <code>__get__<\/code> \u0438 (<code>__set__<\/code> \u0438\u043b\u0438 <code>__delete__<\/code>):<\/p>\n<pre><code class=\"python\">class StaticValueDescriptor:     def __init__(self, value: Any) -> None:         self._value = value          def __set_name__(self, owner, attr_name: str) -> None:         self._protected_attr_name = f\"_{attr_name}\"      def __get__(self, instance, owner=None) -> None:         return self._value      def __set__(self, instance, value: Any) -> None:         setattr(instance, self._protected_attr_name, value)           class Object:     attr_1 = StaticValueDescriptor(100)          def __init__(self):         self.attr_1 = 200           object_ = Object() object_.attr_1  # -> 100 - data descriptor \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442                 # \u043d\u0430\u0434 __dict__ \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430<\/code><\/pre>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043d\u0430\u043c \u0437\u0430\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c\/\u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>__set__<\/code>, \u0438 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c <strong>non-data descriptor<\/strong>, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u0435\u043d\u044c\u0448\u0438\u0439 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442, \u0447\u0435\u043c \u0443 <code>__dict__<\/code> \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<pre><code class=\"python\">class StaticValueDescriptor:     ...          # def __set__(self, instance, value: Any) -> None:     #    setattr(instance, self._private_attr_name, value)       class Object:     attr_1 = StaticValueDescriptor(100)          def __init__(self):         self.attr_1 = 200           object_ = Object() object_.attr_1  # -> 200<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u043e\u0432, \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0432\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f \u043a \u043d\u0430\u0447\u0430\u043b\u0443 \u0441\u0442\u0430\u0442\u044c\u0438 \u0438 \u043e\u0431\u0441\u0443\u0434\u0438\u0442\u044c \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0430\u043a \u0438\u043b\u0438 \u0438\u043d\u0430\u0447\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u044b \u0441 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u0430\u043c\u0438. \u042f \u043f\u043e\u043a\u0430\u0436\u0443 \u043e\u0434\u043d\u0443 \u0438\u0437 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439 \u044d\u0442\u0438\u0445 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u0432 \u043d\u0430 <strong>python<\/strong>.<\/p>\n<p><strong>staticmethod<\/strong> &#8212; \u042d\u0442\u043e <strong>non-data descriptor<\/strong> \u0441 \u043e\u0434\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 &#8212; \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0442\u043e\u0442 \u0436\u0435 \u043c\u0435\u0442\u043e\u0434, \u0447\u0442\u043e \u0438 \u0431\u044b\u043b \u043f\u043e\u043b\u0443\u0447\u0435\u043d. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u0441\u044f \u043e\u0442 <strong>self<\/strong>.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a3d\/ae8\/41f\/a3dae841f9733c1e045d59b7e0dbb66e.png\" alt=\"\u0412\u0430\u0448\u0430 idea \u043c\u043e\u0436\u0435\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0443, \u043d\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432\u0441\u0451 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.\" title=\"\u0412\u0430\u0448\u0430 idea \u043c\u043e\u0436\u0435\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0443, \u043d\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432\u0441\u0451 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.\" width=\"526\" height=\"143\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a3d\/ae8\/41f\/a3dae841f9733c1e045d59b7e0dbb66e.png\"\/><\/p>\n<div><figcaption>\u0412\u0430\u0448\u0430 <strong>idea<\/strong> \u043c\u043e\u0436\u0435\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0443, \u043d\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432\u0441\u0451 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.<\/figcaption><\/div>\n<\/figure>\n<pre><code class=\"python\">class StaticMethod:     def __init__(self, method: Callable) -> None:         self._method = method          def __get__(self, instance, owner=None) -> Any:         return self._method         class Object:     @StaticMethod     def attr_1():         return 100         object_ = Object() object_.attr_1()  # -> 100<\/code><\/pre>\n<p><strong>classmethod<\/strong> &#8212; \u041d\u0435 \u0447\u0442\u043e \u0438\u043d\u043e\u0435, \u043a\u0430\u043a <strong>non-data descriptor<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u043e\u0431\u0451\u0440\u0442\u043a\u0443 \u043d\u0430\u0434 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c, \u0438 \u0432\u043c\u0435\u0441\u0442\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430(<strong>self<\/strong>), \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442 \u043f\u0435\u0440\u0432\u044b\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u043a\u043b\u0430\u0441\u0441(<strong>cls<\/strong>).<\/p>\n<pre><code class=\"python\">class ClassMethod:     def __init__(self, method: Callable) -> None:         self._method = method          def __get__(self, instance, owner=None) -> Any:         @wraps(self._method)         def wrapper(*args, **kwargs):             return self._method(owner, *args, **kwargs)         return wrapper         class Object:     @ClassMethod     def attr_1(cls):         return cls         object_ = Object() object_.attr_1()  # -> &lt;class 'main.Object'><\/code><\/pre>\n<p><strong>property <\/strong>&#8212; \u0412 \u0443\u0433\u043e\u0434\u0443 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044e, \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0443\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u0432\u043e \u0432\u0441\u0435\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f\u0445 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0431\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u0439 \u043d\u0430\u043c <strong>property<\/strong>. \u041e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u0438 \u0431\u0430\u0437\u043e\u0432\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438, \u043e\u043d \u0434\u0435\u043b\u0430\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u043e\u0442 \u043d\u0435\u0433\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f:<\/p>\n<pre><code class=\"python\">class Property:     def __init__(         self,         fget: Callable | None = None,         fset: Callable | None = None,         fdel: Callable | None = None,     ) -> None:         self._fget = fget         self._fset = fset         self._fdel = fdel          def getattr(self, fget: Callable) -> Property:         return type(self)(fget, self._fset, self._fdel)          def setattr(self, fset: Callable) -> Property:         return type(self)(self._fget, fset, self._fdel)          def deleter(self, fdel: Callable) -> Property:         return type(self)(self._fget, self._fset, fdel)          def __get__(self, instance, owner=None) -> Any:         return self._fget(instance)          def __set__(self, instance, value) -> None:         self._fset(instance, value)          def __delete__(self, instance) -> None:         self._fdel(instance)           class Object:     def __init__(self, value: Any) -> None:         self._attr_1 = value              @Property     def attr_1(self):         return self._attr_1      @attr_1.setattr     def attr_1(self, value: Any) -> None:         self._attr_1 = value              @attr_1.deleter     def attr_1(self) -> None:         self._attr_1 = None           object_ = Object(100) object_.attr_1  # -> 100 object_.attr_1 = 200 object_.attr_1  # -> 200 del object_.attr_1 object_.attr_1  # -> None<\/code><\/pre>\n<p>\u0418 \u0432 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u0431\u0435\u0437 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e <code>__slots__<\/code> \u0442\u043e\u0436\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u0430\u043c:<\/p>\n<pre><code class=\"python\">class Object:     __slots__ = (\"attr_1\", \"attr_2\")       type(Object.attr_1)  # -> &lt;class 'member_descriptor'> type(Object.attr_2)  # -> &lt;class 'member_descriptor'><\/code><\/pre>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0432\u0441\u0435\u043c, \u043a\u0442\u043e \u0441\u043f\u0440\u0430\u0432\u0438\u043b\u0441\u044f \u0438 \u0434\u043e\u0447\u0438\u0442\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u044e \u0434\u043e \u043a\u043e\u043d\u0446\u0430! \u042d\u0442\u043e \u0431\u044b\u043b\u0430 \u0432\u0432\u043e\u0434\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043e \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u0430\u0445. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u044f \u043d\u0430\u043f\u0438\u0448\u0443 \u0432\u0442\u043e\u0440\u0443\u044e \u0447\u0430\u0441\u0442\u044c, \u0438 \u043f\u043e\u043a\u0430\u0436\u0443 \u043a\u0430\u043a\u0438\u0435 \u0435\u0449\u0451 \u0432\u0435\u0449\u0438 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430.<\/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\/811777\/\"> https:\/\/habr.com\/ru\/articles\/811777\/<\/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>\u0415\u0441\u043b\u0438 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u0442\u043e <strong>\u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440<\/strong> \u2014 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c <strong>\u043f\u043e\u0438\u0441\u043a<\/strong>, <strong>\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435<\/strong> \u0438 <strong>\u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435<\/strong> \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432.<\/p>\n<p>\u0414\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u043a\u043b\u0430\u0441\u0441\u0430\u0445, \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u044f \u0432 \u0440\u043e\u043b\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430(\u043d\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430). <\/p>\n<p>\u0414\u0443\u043c\u0430\u044e, \u043c\u0430\u043b\u043e \u043a\u0442\u043e, \u0445\u043e\u0442\u044f \u0431\u044b \u0440\u0430\u0437, \u0441\u0430\u043c \u043f\u0438\u0441\u0430\u043b \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b \u0432 \u043a\u043e\u043c\u043c\u0435\u0440\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435, \u043d\u043e \u044f \u0443\u0432\u0435\u0440\u0435\u043d, \u0447\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u0430\u043c\u0438, \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0438\u0445 &#171;\u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c&#187;:<\/p>\n<ul>\n<li>\n<p><code>classmethod<\/code>, <code>staticmethod<\/code><\/p>\n<\/li>\n<li>\n<p><code>property<\/code><\/p>\n<\/li>\n<li>\n<p><code>__slots__<\/code> <\/p>\n<\/li>\n<li>\n<p>\u0412 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435, \u043b\u044e\u0431\u043e\u0435 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0443 \u043a\u043b\u0430\u0441\u0441\u0430, \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u0430\u043c\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043d\u0438\u0445, \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0441 \u0432\u0430\u043c\u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0437\u0434\u043d\u0435\u0435.<\/p>\n<p>\u041f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u043e\u0432 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437:<\/p>\n<ul>\n<li>\n<p><code>__get__<\/code> &#8212; \u041f\u043e\u0438\u0441\u043a \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430<\/p>\n<\/li>\n<li>\n<p><code>__set__<\/code> &#8212; \u0425\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430<\/p>\n<\/li>\n<li>\n<p><code>__delete__<\/code>  &#8212; \u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u043f\u043e\u0438\u0441\u043a\u0430 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 &#8212; <code>__get__<\/code> . <\/p>\n<pre><code class=\"python\">class StaticValueDescriptor:     def __init__(self, value: Any) -> None:         self._value = value              def __get__(self, instance, owner=None) -> Any:         return self._value     class Object:     attr_1 = StaticValueDescriptor(100)       instance_object = Object() instance_object.attr_1  # -> 100<\/code><\/pre>\n<p>\u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0432 <strong>attr_1<\/strong> \u043c\u044b \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u043b\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <strong>StaticValueDescriptor<\/strong>, \u0432 \u043e\u0442\u0432\u0435\u0442\u0435 \u043c\u044b \u0432\u0438\u0434\u0438\u043c <strong>100<\/strong>, \u043d\u043e \u043f\u043e\u0447\u0435\u043c\u0443?<\/p>\n<p>\u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u0438 \u043f\u043e\u0438\u0441\u043a\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u043a\u043b\u0430\u0441\u0441\u0430(<strong>getattribute<\/strong>), <strong>python<\/strong> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c(<u>\u043f\u043e\u0434\u0447\u0435\u0440\u043a\u043d\u0443\u043b<\/u> \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u043a\u0443\u0441\u043a\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430):<\/p>\n<ul>\n<li>\n<p><strong>attr_1 <\/strong>\u0435\u0441\u0442\u044c \u0432 <code>__dict__<\/code> \u043a\u043b\u0430\u0441\u0441\u0430?<\/p>\n<ul>\n<li>\n<p>\u0414\u0430. \u0415\u0441\u0442\u044c \u043b\u0438 \u0443 \u043d\u0435\u0433\u043e <code>__get__<\/code> \u0438 (<code>__set__<\/code> \u0438\u043b\u0438 <code>__delete__<\/code>)(data descriptor)?<\/p>\n<ul>\n<li>\n<p>\u0414\u0430. \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440.<\/p>\n<\/li>\n<li>\n<p><u>\u041d\u0435\u0442. <\/u><strong><u>attr_1 <\/u><\/strong><u>\u0435\u0441\u0442\u044c \u0432 <\/u><code>__dict__<\/code><u> \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430?<\/u><\/p>\n<ul>\n<li>\n<p><u>\u0414\u0430. \u0412\u0435\u0440\u043d\u0443\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438\u0437 <\/u><code>__dict__<\/code><u> \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430.<\/u><\/p>\n<\/li>\n<li>\n<p><u>\u041d\u0435\u0442. <\/u><strong><u>attr_1 <\/u><\/strong><u>\u0435\u0441\u0442\u044c \u0432 <\/u><code>__dict__<\/code><u> \u043a\u043b\u0430\u0441\u0441\u0430?<\/u><\/p>\n<ul>\n<li>\n<p><u>\u0414\u0430. \u0415\u0441\u0442\u044c \u043b\u0438 \u0443 \u043d\u0435\u0433\u043e <\/u><code>__get__<\/code><u> (non-data descriptor)?<\/u><\/p>\n<ul>\n<li>\n<p><u>\u0414\u0430. \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440.<\/u><\/p>\n<\/li>\n<li>\n<p><u>\u041d\u0435\u0442. \u0412\u0435\u0440\u043d\u0443\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438\u0437 <\/u><code>__dict__<\/code><u> \u043a\u043b\u0430\u0441\u0441\u0430.<\/u><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><u>\u041d\u0435\u0442. \u0412\u044b\u0437\u043e\u0432 \u0443 \u043a\u043b\u0430\u0441\u0441\u0430 <\/u><code>getattr<\/code><u> , \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432\u043e\u0437\u0431\u0443\u0434\u0438\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 <\/u><strong><u>AttributeError.<\/u><\/strong><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><u>\u041d\u0435\u0442. <\/u><strong><u>attr_1 <\/u><\/strong><u>\u0435\u0441\u0442\u044c \u0432 <\/u><code>__dict__<\/code><u> \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430?<\/u><\/p>\n<ul>\n<li>\n<p><u>\u0414\u0430. \u0412\u0435\u0440\u043d\u0443\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438\u0437 <\/u><code>__dict__<\/code><u> \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430.<\/u><\/p>\n<\/li>\n<li>\n<p><u>\u041d\u0435\u0442. <\/u><strong><u>attr_1 <\/u><\/strong><u>\u0435\u0441\u0442\u044c \u0432 <\/u><code>__dict__<\/code><u> \u043a\u043b\u0430\u0441\u0441\u0430?<\/u><\/p>\n<ul>\n<li>\n<p><u>\u0414\u0430. \u0415\u0441\u0442\u044c \u043b\u0438 \u0443 \u043d\u0435\u0433\u043e <\/u><code>__get__<\/code><u> (non-data descriptor)?<\/u><\/p>\n<ul>\n<li>\n<p><u>\u0414\u0430. \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440.<\/u><\/p>\n<\/li>\n<li>\n<p><u>\u041d\u0435\u0442. \u0412\u0435\u0440\u043d\u0443\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438\u0437 <\/u><code>__dict__<\/code><u> \u043a\u043b\u0430\u0441\u0441\u0430.<\/u><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><u>\u041d\u0435\u0442. \u0412\u044b\u0437\u043e\u0432 \u0443 \u043a\u043b\u0430\u0441\u0441\u0430 <\/u><code>getattr<\/code><u> , \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432\u043e\u0437\u0431\u0443\u0434\u0438\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 <\/u><strong><u>AttributeError.<\/u><\/strong><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u0421\u043e\u0433\u043b\u0430\u0441\u0435\u043d, \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c, \u0442\u0430\u043a\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043f\u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u043c. \u042f \u0443\u043f\u0440\u043e\u0449\u0443 \u0435\u0433\u043e \u0438 \u043f\u043e\u043a\u0430\u0436\u0443 \u043b\u0438\u0448\u044c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u044b \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u043f\u0440\u0438 \u043f\u043e\u0438\u0441\u043a\u0435:<\/p>\n<ol>\n<li>\n<p><strong>Data descriptor<\/strong> &#8212; \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0435\u0441\u0442\u044c <code>__get__<\/code> \u0438 (<code>__set__<\/code> \u0438\u043b\u0438 <code>__delete__<\/code>)<\/p>\n<\/li>\n<li>\n<p><code>Instance.__dict__<\/code> <\/p>\n<\/li>\n<li>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0434\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0438\u043c\u0435\u044e\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442.<\/p>\n<ol>\n<li>\n<p><strong>Non-data descriptor<\/strong> &#8212; \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e <code>__get__<\/code> <\/p>\n<\/li>\n<li>\n<p><code>Class.__dict__<\/code><\/p>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>\u041c\u044b \u0435\u0449\u0451 \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u0432 \u043d\u0430 \u0434\u0435\u043b\u0435, \u0430 \u043f\u043e\u043a\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0443 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u043e\u0432.<\/p>\n<p>\u0415\u0449\u0451 \u043d\u0435 \u0434\u043e\u0439\u0434\u044f \u0434\u043e <code>__set__<\/code> \u0438\u043b\u0438 <code>__delete__<\/code> \u0443 \u0432\u0430\u0441, \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441 &#8212; &#171;\u0430 \u043a\u0430\u043a \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 \u0441 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u043c? \u042f \u043d\u0435 \u0445\u043e\u0447\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0445\u0430\u0440\u0434\u043a\u043e\u0434\u043d\u044b\u0435 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b&#187;. \u0418 \u043f\u0440\u0430\u0432\u0434\u0430, \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e <strong>StaticValueDescriptor <\/strong>\u0438\u043c\u0435\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u0437\u043a\u0443\u044e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u043e\u0441\u0442\u044c.<\/p>\n<p>\u0420\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u0441 \u0445\u043e\u0434\u0443 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 <code>__init__<\/code>. \u0418 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0440\u0430\u0437\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c <code>__set__<\/code>:<\/p>\n<pre><code class=\"python\">class DataDescriptor:     def __init__(self, attr_name: str) -> None:         self._attr_name = attr_name          def __get__(self, instance, owner=None) -> Any:         return instance.__dict__[self._attr_name]      def __set__(self, instance, value: Any) -> None:         instance.__dict__[self._attr_name] = value           class Object:   attr_1 = DataDescriptor(\"attr_1\")     instance_object = Object() instance_object.attr_1 = 100 instance_object.attr_1  # -> 100<\/code><\/pre>\n<p>\u0412 \u0446\u0435\u043b\u043e\u043c \u043c\u044b \u0440\u0435\u0448\u0438\u043b\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u0438 \u0441\u043c\u043e\u0433\u043b\u0438 \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0438\u043c\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043a\u043b\u0430\u0441\u0441\u0430, \u0433\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <strong>\u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440<\/strong>, \u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0449\u0451 \u043b\u0443\u0447\u0448\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>__set_name__<\/code>:<\/p>\n<pre><code class=\"python\">class DataDescriptor:     def __set_name__(self, owner, attr_name: str) -> None:         self._attr_name = attr_name      def __get__(self, instance, owner=None) -> Any:         return instance.__dict__[self._attr_name]      def __set__(self, instance, value: Any) -> None:         instance.__dict__[self._attr_name] = value           class Object:     attr_1 = DataDescriptor()       instance_object = Object() instance_object.attr_1 = 100 instance_object.attr_1  # -> 100<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0442\u043e\u0434 <code>__set_name__<\/code> \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0441\u043d\u0430\u0440\u0443\u0436\u0438. \u0425\u043e\u0442\u044f \u0443\u0432\u0435\u0440\u0435\u043d, \u043d\u0430\u0439\u0434\u0443\u0442\u0441\u044f \u0442\u0435, \u043a\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u044d\u0442\u043e:<\/p>\n<pre><code class=\"python\">class DataDescriptor:     def __init__(self, attr_name: str) -> None:         self._attr_name = attr_name          def __get__(self, instance, owner=None) -> Any:         return instance.__dict__[self._attr_name]      def __set__(self, instance, value: Any) -> None:         instance.__dict__[self._attr_name] = value           class Object:     attr_1 = DataDescriptor(\"attr_999\")  # \u041d\u0435 \u043d\u0430\u0434\u043e \u0442\u0430\u043a ?      def __init__(self):         self.attr_1 = 123           instance_object = Object() instance_object.attr_999  # -> 123<\/code><\/pre>\n<p>\u041d\u0443 \u0438 \u043d\u0430\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a \u0443 \u043d\u0430\u0441 \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f <code>__delete__<\/code> :<\/p>\n<pre><code class=\"python\">class DataDescriptor:     def __set_name__(self, owner, attr_name: str) -> None:         self._attr_name = attr_name          def __get__(self, instance, owner=None) -> Any:         return instance.__dict__[self._attr_name]      def __set__(self, instance, value: Any) -> None:         instance.__dict__[self._attr_name] = value          def __delete__(self, instance) -> None:         del instance.__dict__[self._attr_name]           class Object:     attr_1 = DataDescriptor()       instance_object = Object() instance_object.attr_1 = 100 instance_object.attr_1  # -> 100 del instance_object.attr_1 instance_object.attr_1  # -> KeyError: 'attr_1'<\/code><\/pre>\n<p>\u041d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0441\u043c\u0443\u0449\u0430\u0435\u0442? \u0410 \u0447\u0442\u043e \u044d\u0442\u043e \u0437\u0430 <strong>KeyError<\/strong> \u043f\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u043a\u043b\u0430\u0441\u0441\u0430? \u041d\u0435\u043f\u043e\u0440\u044f\u0434\u043e\u043a!<\/p>\n<p>\u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 <code>__get__<\/code> , \u043d\u0430\u0448\u0430 \u043f\u043e\u043f\u044b\u0442\u043a\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438\u0437 <code>instance.__dict__<\/code>  \u0442\u0435\u0440\u043f\u0438\u0442 \u043d\u0435\u0443\u0434\u0430\u0447\u0443, \u0442\u0430\u043a \u043a\u0430\u043a \u0442\u0430\u043a\u043e\u0433\u043e <strong>\u043a\u043b\u044e\u0447\u0430<\/strong> \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435 \u043d\u0435\u0442.<\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 <strong>KeyError<\/strong> \u0432 <code>__get__<\/code> , <code>__set__<\/code> , <code>__delete__<\/code> \u0438 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0443, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u043c\u0443 \u0432\u044b\u0448\u0435. \u041a\u0430\u0436\u0435\u0442\u0441\u044f, \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0440\u0443\u043a\u0430\u043c\u0438, \u043d\u0435\u043f\u0440\u0430\u0432\u0434\u0430 \u043b\u0438? \u0412\u044b\u0445\u043e\u0434 \u0435\u0441\u0442\u044c!<\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u0448\u0430\u0433 &#8212; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b(<strong>getattr<\/strong>, <strong>setattr<\/strong>, <strong>delattr<\/strong>), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0430\u0434\u0443\u0442 \u043d\u0430\u043c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"python\">class DataDescriptor:     def __set_name__(self, owner, attr_name: str) -> None:         self._attr_name = attr_name          def __get__(self, instance, owner=None) -> Any:         return getattr(instance, self._attr_name)      def __set__(self, instance, value: Any) -> None:         setattr(instance, self._attr_name, value)          def __delete__(self, instance) -> None:         delattr(instance, self._attr_name)           class Object:     attr_1 = DataDescriptor()       instance_object = Object() instance_object.attr_1 = 100 instance_object.attr_1  # -> 100 del instance_object.attr_1 instance_object.attr_1  # -> RecursionError: maximum recursion depth                         # exceeded while calling a Python object <\/code><\/pre>\n<p>\u041a\u0430\u0436\u0435\u0442\u0441\u044f, \u0443 \u043d\u0430\u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b? \u041f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a <strong>attr_1 <\/strong>\u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435<strong>:<\/strong><\/p>\n<ul>\n<li>\n<p>\u041c\u044b \u0432\u0441\u0451 \u043f\u043e \u0442\u043e\u043c\u0443 \u0436\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0443 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 \u0438 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u043c \u0432 <code>__get__<\/code> . <\/p>\n<\/li>\n<li>\n<p>\u0412\u043d\u0443\u0442\u0440\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>getattr(instance, self._attr_name, value)<\/code> <\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u0442\u043e\u0440\u044b\u0439, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u0437 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 <strong>attr_1<\/strong>(\u043f\u043e \u0441\u0443\u0442\u0438, \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0447\u0442\u043e \u043c\u044b \u043f\u044b\u0442\u0430\u043b\u0438\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e)<\/p>\n<\/li>\n<li>\n<p>\u0418 \u043c\u044b \u0441\u043d\u043e\u0432\u0430 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u043c \u0432 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 \u0438 \u0442\u0430\u043a \u043f\u043e \u043a\u0440\u0443\u0433\u0443.<\/p>\n<\/li>\n<\/ul>\n<p>\u0418 \u043d\u0430 \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0435\u0441\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435! <\/p>\n<p>\u0412\u0442\u043e\u0440\u043e\u0439 \u0448\u0430\u0433 &#8212; \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u0449\u0438\u0449\u0451\u043d\u043d\u044b\u0439(<strong>protected<\/strong>) \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0438\u043c\u0435\u043d\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430:<\/p>\n<pre><code class=\"python\">class DataDescriptor:     def __set_name__(self, owner, attr_name: str) -> None:         self._protected_attr_name = f\"_{attr_name}\"          def __get__(self, instance, owner=None) -> Any:         return getattr(instance, self._protected_attr_name)      def __set__(self, instance, value: Any) -> None:         setattr(instance, self._protected_attr_name, value)          def __delete__(self, instance) -> None:         delattr(instance, self._protected_attr_name)   class Object:     attr_1 = DataDescriptor()       instance_object = Object() instance_object.attr_1 = 100 instance_object.attr_1  # -> 100 del instance_object.attr_1 instance_object.attr_1  # -> AttributeError: 'Object' object has no attribute                         # '_attr_1'. Did you mean: 'attr_1'?<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0434\u043e\u0431\u0438\u043b\u0438\u0441\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438! <\/p>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u0432\u0430\u0441 \u0437\u0430\u0434\u0430\u0434\u0443\u0442\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c &#8212; &#171;\u041a\u0443\u0434\u0430 \u0434\u0435\u043b\u0430\u0441\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0435\u0439? \u041a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0432 \u043a\u043e\u0434\u0435 \u043d\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439.&#187;<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c, \u0447\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u043a <strong>attr_1<\/strong>:<\/p>\n<ul>\n<li>\n<p>\u041c\u044b \u0432\u0441\u0451 \u043f\u043e \u0442\u043e\u043c\u0443 \u0436\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0443 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 \u0438 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u043c \u0432 <code>__get__<\/code> .<\/p>\n<\/li>\n<li>\n<p>\u0412\u043d\u0443\u0442\u0440\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>getattr(instance, self._attr_name, value)<\/code><\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u0437 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0435 <strong>attr_1,<\/strong> \u0430 <strong>_attr_1<\/strong>. <strong>_attr_1<\/strong> \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u043e\u043c \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435 \u043f\u043e\u0432\u043b\u0435\u0447\u0451\u0442 \u0437\u0430 \u0441\u043e\u0431\u043e\u0439 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 <code>__get__<\/code> \u0438 \u0437\u0430\u0446\u0438\u043a\u043b\u0438\u0432\u0430\u043d\u0438\u0435, \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0449\u0435\u0435 \u043a \u043e\u0448\u0438\u0431\u043a\u0435(<strong>RecursionError<\/strong>)<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u0431\u0443\u0434\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0430\u0442\u0440\u0438\u0431\u0443\u0442 <code>_attr_1<\/code> , \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u043e\u043c:<\/p>\n<pre><code class=\"python\">instance_object = Object() instance_object.__dict__  # -> {} instance_object.attr_1 = 100 instance_object.__dict__  # -> {\"_attr_1\": 100}<\/code><\/pre>\n<p>\u0418 \u043d\u0430\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u043c\u0435\u0436\u0434\u0443 <strong>data<\/strong> \u0438 <strong>non-data<\/strong> \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u0430\u043c\u0438. \u041e\u043d\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u0430\u0445 \u043f\u043e\u0438\u0441\u043a\u0430 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430.<\/p>\n<p><strong>Data descriptor<\/strong> \u0438\u043c\u0435\u0435\u0442 <code>__get__<\/code> \u0438 (<code>__set__<\/code> \u0438\u043b\u0438 <code>__delete__<\/code>):<\/p>\n<pre><code class=\"python\">class StaticValueDescriptor:     def __init__(self, value: Any) -> None:         self._value = value          def __set_name__(self, owner, attr_name: str) -> None:         self._protected_attr_name = f\"_{attr_name}\"      def __get__(self, instance, owner=None) -> None:         return self._value      def __set__(self, instance, value: Any) -> None:         setattr(instance, self._protected_attr_name, value)           class Object:     attr_1 = StaticValueDescriptor(100)          def __init__(self):         self.attr_1 = 200           object_ = Object() object_.attr_1  # -> 100 - data descriptor \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442                 # \u043d\u0430\u0434 __dict__ \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430<\/code><\/pre>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043d\u0430\u043c \u0437\u0430\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c\/\u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>__set__<\/code>, \u0438 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c <strong>non-data descriptor<\/strong>, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u0435\u043d\u044c\u0448\u0438\u0439 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442, \u0447\u0435\u043c \u0443 <code>__dict__<\/code> \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<pre><code class=\"python\">class StaticValueDescriptor:     ...          # def __set__(self, instance, value: Any) -> None:     #    setattr(instance, self._private_attr_name, value)       class Object:  <\/code><\/pre>\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-375220","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/375220","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=375220"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/375220\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=375220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=375220"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=375220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}