-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improve typing in inspect #6020
Conversation
This comment has been minimized.
This comment has been minimized.
stdlib/inspect.pyi
Outdated
def __init__( | ||
self, parameters: Sequence[Parameter] | None = ..., *, return_annotation: Any = ..., __validate_parameters__: bool = ... | ||
) -> None: ... | ||
empty: ClassVar[Type[_empty]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you try just writing empty = _empty
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I did and Python 3.10 complains
inspect.Signature.empty variable differs from runtime type Literal[<class 'inspect._empty'>]
and 3.8 and 3.9
inspect.Signature.empty variable differs from runtime type builtins.type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume stubtest complains, but the other tests run? In that case, I'd suggest to just silence the stubtest warnings. But maybe @hauntsaninja has a different opinion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like it should be fine? Not sure what type checkers think of type aliases within class scope, possible something like that is what's throwing stubtest off
Diff from mypy_primer, showing the effect of this PR on open source code: sphinx (https://github.com/sphinx-doc/sphinx.git)
+ sphinx/util/inspect.py:670: error: unused "type: ignore" comment
+ sphinx/util/inspect.py: note: In function "signature_from_ast":
+ sphinx/util/inspect.py:802:27: error: Incompatible types in assignment (expression has type "DefaultValue", variable has type "_empty")
+ sphinx/util/inspect.py:812:23: error: Incompatible types in assignment (expression has type "DefaultValue", variable has type "_empty")
|
I hope I implemented the private marker
_empty
and_void
correctly 😄