-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add mypy plugin support to stubtest configuration #13948
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
base: main
Are you sure you want to change the base?
Add mypy plugin support to stubtest configuration #13948
Conversation
This PR adds support for mypy plugins in stubtest configuration, which enables packages like Django-based stubs to run stubtest correctly. I've demonstrated this functionality in the recently created Key additions:
I'd appreciate your feedback on this implementation and any suggestions for improvement. Thanks for your time! |
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.
Just one nit below. I think this is a useful addition to our test infrastructure, but I'll wait for other maintainer's opinions before merging.
lib/ts_utils/metadata.py
Outdated
@@ -42,6 +42,10 @@ def _is_list_of_strings(obj: object) -> TypeGuard[list[str]]: | |||
return isinstance(obj, list) and all(isinstance(item, str) for item in obj) | |||
|
|||
|
|||
def _is_nested_dict(obj: object) -> TypeGuard[dict[str, dict[str, Any]]]: | |||
return isinstance(obj, dict) and all(isinstance(item, dict) for item in obj.values()) |
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.
Let's test the key also while we're here:
return isinstance(obj, dict) and all(isinstance(item, dict) for item in obj.values()) | |
return isinstance(obj, dict) and all(isinstance(k, str) and isinstance(v, dict) for k, v in obj.items()) |
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.
Affirmative, thank you
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 think that supporting more complex stubs is great, if and only if other type checkers do not have any problems with that in the result.
The code looks good to me, thank you.
Add mypy plugin support for stubtest
This PR adds support for mypy plugins in stubtest configuration, allowing packages that depend on plugins (like Django) to be properly validated. Implements
mypy_plugins
andmypy_plugins_config
fields in METADATA.toml.Fixes #13935