-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix handling of typing.Optional in stubgen #17197
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: master
Are you sure you want to change the base?
Conversation
I am sorry in advance, I have not created any tests as I am unsure how your test suite is setup. |
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.
Thank you for working on this.
Stubgen tests are in this file https://github.com/python/mypy/blob/master/test-data/unit/stubgen.test. You can look at existing test cases for inspiration. You can test stubgen in --inspect-mode
by including # flags: --inspect-mode
as the first line of the test case.
if types or static_properties or rw_properties or methods or ro_properties: | ||
if ( | ||
types | ||
or static_properties | ||
or rw_properties | ||
or methods | ||
or ro_properties | ||
or class_info.docstring | ||
): |
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.
Is this related to the issue with Optional
? I think this change (and the one below) are causing the CI failure.
…o PEP 604 unions (#17386) This Fixes 2 issues with invalid `Optional` (inspired by an error reported in #17197): - do not crash on empty `Optional` - treat `Optional` with more than one index as an unknown type instead of choosing the first type. It also fixes PEP 604 unions not being recognized as type aliases.
When running stubgen on my local repository I noticed a couple of errors occurring notably around the handling of typing.Union / typing.Optional when
--inspect-mode
was being used.I am running Python 3.10.14 on Linux.
I put together a mre:
I put this in
mre.py
then ran:I would get:
calling
get_annotations(arg)
fixed this as the object being passed through was <class 'int'> and not the string versionthis was because
Optional[int]
was becomingtyping.Optional
and nottyping.Optional[int]
I updated handling to pass the[int]
through (this may be incorrect though)