Title: Disable the special `__setattr__` handling · Issue #12696 · python/mypy · GitHub
Open Graph Title: Disable the special `__setattr__` handling · Issue #12696 · python/mypy
X Title: Disable the special `__setattr__` handling · Issue #12696 · python/mypy
Description: Feature I'd like to be able to disable the behavior introduced in #3451 where defining __setattr__ makes mypy assume all property assignments are valid. Pitch Suppose I have a class that logs all attribute accesses: @dataclass class MyCl...
Open Graph Description: Feature I'd like to be able to disable the behavior introduced in #3451 where defining __setattr__ makes mypy assume all property assignments are valid. Pitch Suppose I have a class that logs all a...
X Description: Feature I'd like to be able to disable the behavior introduced in #3451 where defining __setattr__ makes mypy assume all property assignments are valid. Pitch Suppose I have a class that logs a...
Opengraph URL: https://github.com/python/mypy/issues/12696
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Disable the special `__setattr__` handling","articleBody":"**Feature**\r\n\r\nI'd like to be able to disable the behavior introduced in #3451 where defining `__setattr__` makes mypy assume all property assignments are valid.\r\n\r\n**Pitch**\r\n\r\nSuppose I have a class that logs all attribute accesses:\r\n\r\n```\r\n@dataclass\r\nclass MyClass:\r\n field: int\r\n another_field: str\r\n\r\n def __setattr__(self, key: str, val: Any) -> None:\r\n print(f\"You just set {key}!\")\r\n super().__setattr__(key, val)\r\n```\r\n\r\nDefining `__setattr__` means that I can now write `my_class.feild = 123` and mypy won't catch it. My current workaround is to define a free function and do `MyClass.__setattr__ = _setattr`, but that's kind of janky. I'd like to be able to use a magic comment or a magic dunder variable (`__mypy_no_special_setattr_handling__`) to disable this.","author":{"url":"https://github.com/deifactor","@type":"Person","name":"deifactor"},"datePublished":"2022-04-29T20:17:04Z","url":"https://github.com/python/mypy/issues/12696"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ccdb316b-33f3-cf01-0d2c-50ce2f737959 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8C8E:15DE5D:112F24B:169704F:6B000A9C |
| html-safe-nonce | acf2de825cb0a888caa6fcee7b8d2fc966b5e3047705c9550a014081b56d9293 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QzhFOjE1REU1RDoxMTJGMjRCOjE2OTcwNEY6NkIwMDBBOUMiLCJ2aXNpdG9yX2lkIjoiOTQ2NzA2MDY5MDkzMDkxOTk2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 03d2101e4b5475251ee00bfde7cb48e3a3f421932ec56795e78cf0c4957e8af6 |
| hovercard-subject-tag | issue:1221479517 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/mypy/12696/issue_layout |
| twitter:image | https://opengraph.githubassets.com/783e3c4ed37361c90d46a2a3e4727183c7cddea4bcb31eb94b41e41341b0541c/python/mypy/issues/12696 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/783e3c4ed37361c90d46a2a3e4727183c7cddea4bcb31eb94b41e41341b0541c/python/mypy/issues/12696 |
| og:image:alt | Feature I'd like to be able to disable the behavior introduced in #3451 where defining __setattr__ makes mypy assume all property assignments are valid. Pitch Suppose I have a class that logs all a... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | deifactor |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/mypy git https://github.com/python/mypy.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 7053637 |
| octolytics-dimension-repository_nwo | python/mypy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7053637 |
| octolytics-dimension-repository_network_root_nwo | python/mypy |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 16a11879678aaf97e2a42c33ee70830aa084fa37 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width