{"id":1179479,"date":"2023-09-06T15:29:17","date_gmt":"2023-09-06T19:29:17","guid":{"rendered":"https:\/\/www.prime-wow.com\/?p=1179479"},"modified":"2023-09-06T15:29:17","modified_gmt":"2023-09-06T19:29:17","slug":"altering-python-attribute-handling-for-modules","status":"publish","type":"post","link":"https:\/\/www.prime-wow.com\/?p=1179479","title":{"rendered":"[$] Altering Python attribute handling for modules"},"content":{"rendered":"<p>A recent discussion on the <a href=\"https:\/\/discuss.python.org\/\">Python forum<\/a> looked at a way to<br \/>\nprotect module objects (and users) from mistaken attribute assignment and<br \/>\ndeletion.<br \/>\nThere are ways<br \/>\nto get the same effect today, but the mechanism that would be used causes a<br \/>\nperformance penalty for an unrelated, and heavily used, action: attribute<br \/>\nlookup on modules.  Back in\u00a02017, <a href=\"https:\/\/peps.python.org\/pep-0562\/\">PEP\u00a0562<\/a> (&#8220;Module __getattr__<br \/>\nand __dir__&#8221;) set the stage for adding magic methods to module objects; now<br \/>\na new proposal would extend that idea to add <tt>__setattr__()<\/tt> and<br \/>\n<tt>__delattr__()<\/tt> to them.&#013;<br \/>\n&#013;<br \/>\nSource: LWN.net &#8211; <a href=\"https:\/\/lwn.net\/Articles\/943619\/\" target=\"_blank\" rel=\"noopener\">[$] Altering Python attribute handling for modules<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A recent discussion on the Python forum looked at a way to protect module objects (and users) from mistaken attribute assignment and deletion. There are ways to get the same effect today, but the mechanism that would be used causes &hellip; <a href=\"https:\/\/www.prime-wow.com\/?p=1179479\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[72],"tags":[75],"class_list":["post-1179479","post","type-post","status-publish","format-standard","hentry","category-linux","tag-linux"],"_links":{"self":[{"href":"https:\/\/www.prime-wow.com\/index.php?rest_route=\/wp\/v2\/posts\/1179479","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.prime-wow.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.prime-wow.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.prime-wow.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.prime-wow.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1179479"}],"version-history":[{"count":0,"href":"https:\/\/www.prime-wow.com\/index.php?rest_route=\/wp\/v2\/posts\/1179479\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.prime-wow.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1179479"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.prime-wow.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1179479"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.prime-wow.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1179479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}