You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While this would have been great, the motivation for using typing_extensions.TypeVar in the PR was actually because of the existing TypeVar node class. I tried to search for how typeshed uses default= and noticed that TypeVars which use it were still being imported from typing (e.g. contextlib.pyi).
I'm guessing typing.TypeVar(default=) only worked because symbols from typing_extensions are now treated as exactly equivalent as those from typing. Not sure what typeshed's policy on this actually is; type-checkers certainly don't behave the same:
Right, I'm not sure why neither mypy nor pyright is emitting an error in contextlib.pyi on Python <3.13, even though we're passing the default= parameter to typing.TypeVar when it doesn't have that parameter. That seems like a bug in mypy and pyright, and is probably due to the fact that both type checkers extensively special-case TypeVar. I think we shouldn't rely on that bug; we should probably use typing_extensions.TypeVar when we want to provide a default value for the TypeVar.
I was also curious why we hadn't run into this before. It might actually be reasonable for type checkers to allow default= on typing.TypeVar in stubs before Python 3.13 (I assume that's the choice pyright made), but in flake8-pyi we should allow typing_extensions.TypeVar so users can use it to avoid confusion with the runtime behavior.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.