-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Teach stubgen
to work with complex
and unary expressions
#15661
Conversation
The PR title says stubtest -- you mean stubgen, right? |
stubtest
to work with complex
and unary expressionsstubgen
to work with complex
and unary expressions
|
mypy/stubgen.py
Outdated
@@ -1396,6 +1397,8 @@ def is_private_member(self, fullname: str) -> bool: | |||
def get_str_type_of_node( | |||
self, rvalue: Expression, can_infer_optional: bool = False, can_be_any: bool = True | |||
) -> str: | |||
rvalue = self.unwrap_unary_expr(rvalue) |
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'm not sure we should be doing this with all possible rvalue
s. Some unary expressions change the type:
>>> type(-True)
<class 'int'>
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 guess it's pretty unlikely that this would ever come up in real code, but it would still be nice to be correct here imo :)
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.
Hm, ~True
is also a well-known anti-pattern. I agree, I will include only some cases. Like not bool
and +|- int|float|complex
Now I only allow a very small subset of unary expressions. But, ones I allow make a lot of sense and are very common. |
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.
LGTM, thanks!
No description provided.