-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Improvements to stubgenc #14564
Improvements to stubgenc #14564
Conversation
@hauntsaninja if you have some time it'd be great to get your eyes on this PR as well. thanks! There's just one little test left to fix. |
@hauntsaninja do you think you'll have time to review this? |
mypy/stubgenc.py
Outdated
continue | ||
# First try to get the value via getattr. Some descriptors don't | ||
# like calling their __get__ (see bug #1785), so fall back to | ||
# looking in the __dict__. |
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.
This comment seems wrong; the current code discards cases where getattr() fails, it doesn't fall back to the value in __dict__
.
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.
Good catch. This was adapted from inspect.getmembers
and I left the comment unaltered. This is fixed.
@@ -257,10 +314,12 @@ def generate_c_function_stub( | |||
module: ModuleType, | |||
name: str, | |||
obj: object, | |||
known_modules: list[str], |
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.
Maybe make the argument keyword-only here.
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.
Done
name = name[2:-2] | ||
if name in ("float", "bool", "bytes", "int"): | ||
return name | ||
elif name in ("eq", "ne", "lt", "le", "gt", "ge", "contains"): |
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.
This isn't entirely safe as __eq__
and co may return arbitrary types, but it's probably good enough for stubgen.
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.
Good point. I added a comment here to this effect.
Also, the pybind11 test is broken: we lose |
Previously only argument types were inferred
This adds parity with the external rst signature generator. Qt's shiboken binding generator is known to put constructor signatures in class docstrings.
Previously when given 'foo.bar.spangle', it was assumed that 'import foo.bar' should be added, however, it could be that 'bar.spangle' refers to nested objects (such as classes) within 'foo'. This commit improves this inference by using the list of modules passed to stubgen.
simplify the body of generate_c_type_stub
e.g. Union, Tuple, etc.
…ureGenerator This allows specialized SignatureGenerator subclasses to provide the type of self/cls, such as when a TypeVar is present
ddf5918
to
197592e
Compare
197592e
to
7ac691a
Compare
I fixed this. The problem was that |
This should be all ready to merge. |
This bundles together a handful of improvements to stubgenc. Each one has its own commit, but it can be somewhat time consuming to get a PR reviewed and merged, so I'm putting them together for the sake of expediency. I'll break them up if it is preferred.
An overview of the main changes:
__init__
: shiboken binding generator is known to put constructor signatures in class docstrings rather than on__init__
foo.Bar.Spangle
, it was assumed thatimport foo.Bar
should be added, however, it could be thatBar.Spangle
refers to nested classes within the modulefoo
.