Title: How to annotate variables? · Issue #9 · python/typing · GitHub
Open Graph Title: How to annotate variables? · Issue #9 · python/typing
X Title: How to annotate variables? · Issue #9 · python/typing
Description: In mypy there are two ways to annotate a variable: with a # type: comment or a cast expression. The following are equivalent from mypy's POV: result = [] # type: List[int] result = List[int]() Each has its disadvantages: Jython's parser ...
Open Graph Description: In mypy there are two ways to annotate a variable: with a # type: comment or a cast expression. The following are equivalent from mypy's POV: result = [] # type: List[int] result = List[int]() Each...
X Description: In mypy there are two ways to annotate a variable: with a # type: comment or a cast expression. The following are equivalent from mypy's POV: result = [] # type: List[int] result = List[int]() ...
Opengraph URL: https://github.com/python/typing/issues/9
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"How to annotate variables?","articleBody":"In mypy there are two ways to annotate a variable: with a `# type:` comment or a cast expression. The following are equivalent from mypy's POV:\n\n```\n result = [] # type: List[int]\n result = List[int]()\n```\n\nEach has its disadvantages:\n- Jython's parser doesn't preserve comments and they don't want to change the parser\n- The cast expression incurs significant overhead (List[int] creates a new parametrize type object)\n\nThere's no clear solution at this point; something has got to give (though the PEP should probably support both and point out the issues).\n\nFor some specific cases (e.g. a variable initialized to an empty concrete container that is used directly in a 'return' statement) we may be able to improve the type inferencer, but in general that's a path we would rather not take (there's a good reason we start with function annotations only).\n\nIn the future (e.g. Python 3.6 or later) we may be confident enough to introduce variable annotations, e.g.\n\n```\nvar result: List[int] = []\n```\n\nor perhaps even\n\n```\nresult: List[int] = []\n```\n\nBut this remains to be seen, and we definitely don't want to do this for the current PEP or Python 3.5. Plus, it might still incur exactly the same runtime overhead.\n","author":{"url":"https://github.com/gvanrossum","@type":"Person","name":"gvanrossum"},"datePublished":"2014-10-16T02:20:25Z","url":"https://github.com/python/typing/issues/9"}
| 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:74f6a561-a7a9-9c6e-e160-84dec7a8efe2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C2CE:308579:2F49E9:42CB17:6B006CCA |
| html-safe-nonce | 81acce052afdca2f1fad9bdf5bb32003880600694fb2fd9609e3b2ce88c81e82 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMkNFOjMwODU3OToyRjQ5RTk6NDJDQjE3OjZCMDA2Q0NBIiwidmlzaXRvcl9pZCI6Ijk2MDMxMTkzMjc4MTM1ODI4MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | befd2169d8e591d7546a661da0ca320c4e4ab1e0852f97f0862f7f99adbc37b8 |
| hovercard-subject-tag | issue:45941587 |
| 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/typing/9/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ddb4746323c3d1c421979bce43ed6f9e1a10978ed568e8962e04e463665243f4/python/typing/issues/9 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ddb4746323c3d1c421979bce43ed6f9e1a10978ed568e8962e04e463665243f4/python/typing/issues/9 |
| og:image:alt | In mypy there are two ways to annotate a variable: with a # type: comment or a cast expression. The following are equivalent from mypy's POV: result = [] # type: List[int] result = List[int]() Each... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gvanrossum |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6527e91c60c0b29d16606ff32ac5df8ecdc37a2a62205ea057a14d7762c870fa |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typing git https://github.com/python/typing.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 24604008 |
| octolytics-dimension-repository_nwo | python/typing |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24604008 |
| octolytics-dimension-repository_network_root_nwo | python/typing |
| 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 | 46f1cd2ae3cd8ae1a81019b5d619742e76f13bbd |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width