Title: Ask for an explicit annotation if the inferred type is None · Issue #3741 · python/mypy · GitHub
Open Graph Title: Ask for an explicit annotation if the inferred type is None · Issue #3741 · python/mypy
X Title: Ask for an explicit annotation if the inferred type is None · Issue #3741 · python/mypy
Description: Currently mypy behaves like this class C: def __init__(self) -> None: self.x = None def bar(self) -> None: self.x = 42 # Incompatible types in assignment (expression has type "int", variable has type None) This may be non-intuitive for n...
Open Graph Description: Currently mypy behaves like this class C: def __init__(self) -> None: self.x = None def bar(self) -> None: self.x = 42 # Incompatible types in assignment (expression has type "int", variable has ty...
X Description: Currently mypy behaves like this class C: def __init__(self) -> None: self.x = None def bar(self) -> None: self.x = 42 # Incompatible types in assignment (expression has type "int",...
Opengraph URL: https://github.com/python/mypy/issues/3741
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Ask for an explicit annotation if the inferred type is None","articleBody":"Currently mypy behaves like this\r\n```python\r\nclass C:\r\n def __init__(self) -> None:\r\n self.x = None\r\n\r\n def bar(self) -> None:\r\n self.x = 42 # Incompatible types in assignment (expression has type \"int\", variable has type None)\r\n```\r\nThis may be non-intuitive for new users. Instead, it is proposed to either:\r\n* Request an explicit annotation if the inferred type is ``None``, like we would do for ``lst = []``.\r\n* Use partial ``None`` types, like we would do if both assignments were within the same function.\r\n\r\ncc @vlasovskikh","author":{"url":"https://github.com/ilevkivskyi","@type":"Person","name":"ilevkivskyi"},"datePublished":"2017-07-19T19:12:37Z","url":"https://github.com/python/mypy/issues/3741"}
| 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:35712ff5-d190-7ed3-9abf-6a13c598288e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EC5A:3E7030:1FDF8E:2AE0A0:6B0022B5 |
| html-safe-nonce | 430025ddcbda23f090c19473033fea86a6d827c84f4122c1067a803b384e9554 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQzVBOjNFNzAzMDoxRkRGOEU6MkFFMEEwOjZCMDAyMkI1IiwidmlzaXRvcl9pZCI6IjE5MzI2NzQwNjAyMzYzNjY1MTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 3702fd1c49a64f83767bf0f1cda8d185863d1fe660b908012777d0cab39a3fff |
| hovercard-subject-tag | issue:244144279 |
| 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/3741/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8a8e529229f433ab0101a803cb89b90ee5c36b086958c64d2f59a5b232e60c5b/python/mypy/issues/3741 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8a8e529229f433ab0101a803cb89b90ee5c36b086958c64d2f59a5b232e60c5b/python/mypy/issues/3741 |
| og:image:alt | Currently mypy behaves like this class C: def __init__(self) -> None: self.x = None def bar(self) -> None: self.x = 42 # Incompatible types in assignment (expression has type "int", variable has ty... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ilevkivskyi |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| 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 | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width