-
-
Notifications
You must be signed in to change notification settings - Fork 3k
stubgen: properly convert overloaded functions #9613
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
Conversation
| self.add_typing_import("Any") | ||
| annotation = ": {}".format(self.typing_name("Any")) | ||
| elif annotated_type and not is_self_arg: | ||
| elif annotated_type and not is_self_arg and not is_cls_arg: |
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.
without this change I was getting an erroneous type for cls:
class A:
@typing.overload
@classmethod
def g(cls: Any, x: typing.Tuple[int, int]) -> int: ...3a68e56 to
423f912
Compare
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.
Thanks, looks good! I only left one comment. This is ready to merge once it has been addressed.
mypy/stubgen.py
Outdated
| return is_abstract | ||
| elif (isinstance(expr.expr, NameExpr) and | ||
| (expr.expr.name == 'typing' or | ||
| self.import_tracker.reverse_alias.get('typing')) and |
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.
Should this be expr.expr.name in ('typing', self.import_tracker.reverse_alias.get('typing'))? Maybe add test case that uses import typing as t or similar.
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 not working correctly for abc.abstractmethod|property, which is where I copied it from. I fixed it and added a test for both.
d144d15 to
c4a2ce4
Compare
|
This should be all ready to merge |
|
Hi, this is still ready to merge! |
c4a2ce4 to
3e55df1
Compare
Description
Improves
stubgento convert functions that have been decorated with@overload.stubgenis useful not just for creating a starting point for manually authoring stubs, but also to create automated workflows to continuously regenerate stubs for projects that want to provide stubs to third parties to hide runtime complexity from mypy.Test Plan
Added two new tests.