Skip to content

Improve inspect stubs #7050

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

Merged
merged 3 commits into from
Jan 27, 2022
Merged

Improve inspect stubs #7050

merged 3 commits into from
Jan 27, 2022

Conversation

AlexWaygood
Copy link
Member

No description provided.

@github-actions

This comment has been minimized.

@JelleZijlstra
Copy link
Member

I'm not sure making the Signature class generic is really helpful, and the mypy-primer output agrees. It's usually used for introspection, and most code doing that probably doesn't benefit from precise types for the return annotation.

It's also not always correct: your code will infer something like Signature[int] for inspect.signature(lambda: 1), but in fact the signature that computes has no return_annotation.

@AlexWaygood
Copy link
Member Author

It's also not always correct: your code will infer something like Signature[int] for inspect.signature(lambda: 1), but in fact the signature that computes has no return_annotation.

Good point -- I've reverted the changes making it generic. I've also removed the TODO comment, since, from what you're saying (and I agree), it sounds like we can't really be more specific here.

@github-actions

This comment has been minimized.

@@ -166,7 +167,6 @@ class Signature:
empty = _empty
@property
def parameters(self) -> types.MappingProxyType[str, Parameter]: ...
# TODO: can we be more specific here?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's either the empty marker or whatever the user put in an annotation. I don't think we can express that better in the current type system.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

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.

2 participants