Title: (🐞) Call to function decorated with a `Callable` causes inner function to fail to infer type of variable · Issue #8900 · python/mypy · GitHub
Open Graph Title: (🐞) Call to function decorated with a `Callable` causes inner function to fail to infer type of variable · Issue #8900 · python/mypy
X Title: (🐞) Call to function decorated with a `Callable` causes inner function to fail to infer type of variable · Issue #8900 · python/mypy
Description: from typing import Any, Callable, TypeVar, _T as T def bar() -> None: def inner() -> None: it.encode() # error: Cannot determine type of 'it' breaks() it = "" deco: Callable[[T], T] @deco def breaks() -> None: ... It appears that the ord...
Open Graph Description: from typing import Any, Callable, TypeVar, _T as T def bar() -> None: def inner() -> None: it.encode() # error: Cannot determine type of 'it' breaks() it = "" deco: Callable[[T], T] @deco def break...
X Description: from typing import Any, Callable, TypeVar, _T as T def bar() -> None: def inner() -> None: it.encode() # error: Cannot determine type of 'it' breaks() it = "" deco: Callable...
Opengraph URL: https://github.com/python/mypy/issues/8900
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"(🐞) Call to function decorated with a `Callable` causes inner function to fail to infer type of variable","articleBody":"```py\r\nfrom typing import Any, Callable, TypeVar, _T as T\r\n\r\ndef bar() -> None:\r\n def inner() -> None:\r\n it.encode() # error: Cannot determine type of 'it'\r\n breaks()\r\n it = \"\"\r\n \r\ndeco: Callable[[T], T]\r\n\r\n@deco\r\ndef breaks() -> None: ...\r\n```\r\n\r\nIt appears that the order of the function declarations affects the result(:trollface:):\r\n```py\r\nfrom typing import Any, Callable, TypeVar\r\n\r\nT = TypeVar(\"T\")\r\n\r\ndeco: Callable[[T], T]\r\n\r\n@deco\r\ndef doesnt_break() -> None: ...\r\n\r\ndef bar() -> None:\r\n def inner() -> None:\r\n it.encode() # no error\r\n doesnt_break()\r\n it = \"\"\r\n```\r\n\r\n\r\nI have determined that this only happens when the `deco` is a `Callable`, when it is a function there is no error:\r\n\r\n```py\r\nfrom typing import Any, TypeVar, _T as T\r\n\r\ndef bar() -> None:\r\n def inner() -> None:\r\n it.encode() # no error\r\n doesnt_break()\r\n it = \"\"\r\n \r\ndef deco(fn: T) -> T: ...\r\n\r\n@deco\r\ndef doesnt_break() -> None: ...\r\n```\r\n\r\n[playground](https://mypy-play.net/?gist=a2297c66f57365a4def7e340ebfd2ba5)","author":{"url":"https://github.com/KotlinIsland","@type":"Person","name":"KotlinIsland"},"datePublished":"2020-05-27T05:53:23Z","url":"https://github.com/python/mypy/issues/8900"}
| 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:209fe12c-c0c4-2b9f-181d-326cb8e8b8e0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BA82:12476C:1B96F04:24578B4:6B002864 |
| html-safe-nonce | 8f125e918512389d44d591b546c17883921c4efa2c6a16067edc1a06963dcd80 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQTgyOjEyNDc2QzoxQjk2RjA0OjI0NTc4QjQ6NkIwMDI4NjQiLCJ2aXNpdG9yX2lkIjoiMzMwMTQwNTc0ODYzODAwMTI1MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ba3c723a60b9f6466a9c7f8366482eddeb676c3322ac0fa2e1fbe1689dc24d63 |
| hovercard-subject-tag | issue:625399769 |
| 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/8900/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e35134e9b330e69992f84c239c0091fbf9d72fac501801ba0428f3e2707bf8c4/python/mypy/issues/8900 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e35134e9b330e69992f84c239c0091fbf9d72fac501801ba0428f3e2707bf8c4/python/mypy/issues/8900 |
| og:image:alt | from typing import Any, Callable, TypeVar, _T as T def bar() -> None: def inner() -> None: it.encode() # error: Cannot determine type of 'it' breaks() it = "" deco: Callable[[T], T] @deco def break... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | KotlinIsland |
| 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