Title: Nested functions don't take type restrictions into account · Issue #2145 · python/mypy · GitHub
Open Graph Title: Nested functions don't take type restrictions into account · Issue #2145 · python/mypy
X Title: Nested functions don't take type restrictions into account · Issue #2145 · python/mypy
Description: Example: from typing import * def f(a: Union[int, str]) -> int: if isinstance(a, str): return -1 def inner() -> int: return a+1 # E: Unsupported operand types for + ("Union[int, str]" and "int" return inner() Note that when inner() is de...
Open Graph Description: Example: from typing import * def f(a: Union[int, str]) -> int: if isinstance(a, str): return -1 def inner() -> int: return a+1 # E: Unsupported operand types for + ("Union[int, str]" and "int" ret...
X Description: Example: from typing import * def f(a: Union[int, str]) -> int: if isinstance(a, str): return -1 def inner() -> int: return a+1 # E: Unsupported operand types for + ("Union[int, str]&quo...
Opengraph URL: https://github.com/python/mypy/issues/2145
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Nested functions don't take type restrictions into account","articleBody":"Example:\n\n``` python\nfrom typing import *\n\ndef f(a: Union[int, str]) -> int:\n if isinstance(a, str):\n return -1\n def inner() -> int:\n return a+1 # E: Unsupported operand types for + (\"Union[int, str]\" and \"int\"\n return inner()\n```\n\nNote that when inner() is defined, and also when it's called, a can only be an int. But we still get an error.\n\nI ran into this when checking some real-world code against strict optional -- there the union was Optional[int] and the type restriction was `if a is not None`, but it's the same problem.\n","author":{"url":"https://github.com/gvanrossum","@type":"Person","name":"gvanrossum"},"datePublished":"2016-09-15T21:08:47Z","url":"https://github.com/python/mypy/issues/2145"}
| 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:c8cbc8cc-fcab-df55-fec9-e2291b06187f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 80F2:14B836:51407:6E387:6B001A87 |
| html-safe-nonce | 0942099e48567b502d749d7a2831c9be9b0daee02b3b0e866b83c3089c43a006 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MEYyOjE0QjgzNjo1MTQwNzo2RTM4Nzo2QjAwMUE4NyIsInZpc2l0b3JfaWQiOiI4NjkwNjM0MTc3OTczODUyODA3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | a07c38da21ca365745922fc752dc944466b0e90396dc9413ce0407b943f834d2 |
| hovercard-subject-tag | issue:177290577 |
| 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/2145/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f5e4be390a4299736bf7febceb84304cff38a35f3e3897f0edcf7cbb55dac643/python/mypy/issues/2145 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f5e4be390a4299736bf7febceb84304cff38a35f3e3897f0edcf7cbb55dac643/python/mypy/issues/2145 |
| og:image:alt | Example: from typing import * def f(a: Union[int, str]) -> int: if isinstance(a, str): return -1 def inner() -> int: return a+1 # E: Unsupported operand types for + ("Union[int, str]" and "int" ret... |
| 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 | a2dd2291b1b13cc9c06f27ec92fa3dbaf34116fc24c9347b8539db61884c59f4 |
| 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 | 70121d4e855ee0bb7b75cf15d061d91f8863c0f8 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width