Title: Invalid annotation in `SimplePath` protocol · Issue #468 · python/importlib_metadata · GitHub
Open Graph Title: Invalid annotation in `SimplePath` protocol · Issue #468 · python/importlib_metadata
X Title: Invalid annotation in `SimplePath` protocol · Issue #468 · python/importlib_metadata
Description: Hi! I was working on typeshed's types and we (well, @AlexWaygood) found that annotation of __truediv__ is not valid: importlib_metadata/importlib_metadata/_meta.py Lines 55 to 56 in 8e7b968 def __truediv__(self, other: Union[str, _T]) ->...
Open Graph Description: Hi! I was working on typeshed's types and we (well, @AlexWaygood) found that annotation of __truediv__ is not valid: importlib_metadata/importlib_metadata/_meta.py Lines 55 to 56 in 8e7b968 def __t...
X Description: Hi! I was working on typeshed's types and we (well, @AlexWaygood) found that annotation of __truediv__ is not valid: importlib_metadata/importlib_metadata/_meta.py Lines 55 to 56 in 8e7b968 def...
Opengraph URL: https://github.com/python/importlib_metadata/issues/468
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Invalid annotation in `SimplePath` protocol","articleBody":"Hi! \r\n\r\nI was working on `typeshed`'s types and we (well, @AlexWaygood) found that annotation of `__truediv__` is not valid: https://github.com/python/importlib_metadata/blob/8e7b9689fc38ef3e834265fd78423a9933a33607/importlib_metadata/_meta.py#L55-L56\r\n\r\nHere's a small repro: https://mypy-play.net/?mypy=latest&python=3.11&gist=2f16bbbbaf5a1330cbbcae76b5987868\r\n\r\n\r\n```python\r\nfrom typing import TypeVar\r\n\r\nT = TypeVar('T')\r\n\r\nclass A:\r\n def method(self, other: T | str) -> T: ...\r\n\r\na: A\r\nreveal_type(a.method(1)) # N: Revealed type is \"builtins.int\"\r\nreveal_type(a.method('a')) # N: Revealed type is \"\u003cnothing>\"\r\n```\r\n\r\nI propose using an `@overload` instead:\r\n\r\n```python\r\n\r\nfrom typing import TypeVar, overload\r\n\r\nT = TypeVar('T')\r\n\r\nclass A:\r\n @overload\r\n def method(self, other: str) -> str: ...\r\n @overload\r\n def method(self, other: T) -> T: ...\r\n\r\na: A\r\nreveal_type(a.method(1)) # N: Revealed type is \"builtins.int\"\r\nreveal_type(a.method('a')) # N: Revealed type is \"builtins.str\"\r\n```\r\n\r\nPlayground: https://mypy-play.net/?mypy=latest&python=3.11\r\n\r\nI will send a PR with the fix :)","author":{"url":"https://github.com/sobolevn","@type":"Person","name":"sobolevn"},"datePublished":"2023-09-08T11:19:55Z","url":"https://github.com/python/importlib_metadata/issues/468"}
| 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:5dfce6af-d7f4-ab88-1c27-07ee948aa467 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EA72:3ABEF2:35EE12:481548:6B00A06B |
| html-safe-nonce | 8de695f7414cb06d50aeb7bedd2c1123d8ab7df59b86f5dc01b6e46db5e7b9a2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQTcyOjNBQkVGMjozNUVFMTI6NDgxNTQ4OjZCMDBBMDZCIiwidmlzaXRvcl9pZCI6IjcxNTMxNjY5MDgyNzgyMTg4NTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 31c81206aae8cf6d4a8c20e41590a319a32071a2b1656a93dd716f8705d78ec2 |
| hovercard-subject-tag | issue:1887480293 |
| 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/importlib_metadata/468/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0eb679529683011779fb0bfe6ece07edb24bc90464fa4859b05646f43c6c0ea7/python/importlib_metadata/issues/468 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0eb679529683011779fb0bfe6ece07edb24bc90464fa4859b05646f43c6c0ea7/python/importlib_metadata/issues/468 |
| og:image:alt | Hi! I was working on typeshed's types and we (well, @AlexWaygood) found that annotation of __truediv__ is not valid: importlib_metadata/importlib_metadata/_meta.py Lines 55 to 56 in 8e7b968 def __t... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sobolevn |
| hostname | github.com |
| expected-hostname | github.com |
| None | 52c95ce7e48016ae14399656b4ee812462b6f1fa28c5008c8394da64794c00b8 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/importlib_metadata git https://github.com/python/importlib_metadata.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 306448340 |
| octolytics-dimension-repository_nwo | python/importlib_metadata |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 306448340 |
| octolytics-dimension-repository_network_root_nwo | python/importlib_metadata |
| 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 | 1c9ddec8215f9a94e295c8310c3579b9c54ba31a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width