Skip to content
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

Merged
merged 2 commits into from
Sep 19, 2021
Merged

Conversation

gruebel
Copy link
Contributor

@gruebel gruebel commented Sep 10, 2021

I hope I implemented the private marker _empty and _void correctly 😄

@github-actions

This comment has been minimized.

def __init__(
self, parameters: Sequence[Parameter] | None = ..., *, return_annotation: Any = ..., __validate_parameters__: bool = ...
) -> None: ...
empty: ClassVar[Type[_empty]]
Copy link
Collaborator

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?

Copy link
Contributor Author

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

Copy link
Collaborator

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?

Copy link
Collaborator

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

@github-actions
Copy link
Contributor

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")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants