Skip to content
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

Merged
merged 3 commits into from
Jul 13, 2023

Conversation

sobolevn
Copy link
Member

No description provided.

@AlexWaygood
Copy link
Member

The PR title says stubtest -- you mean stubgen, right?

@sobolevn sobolevn changed the title Teach stubtest to work with complex and unary expressions Teach stubgen to work with complex and unary expressions Jul 13, 2023
@sobolevn
Copy link
Member Author

stubgentest 😆

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)
Copy link
Member

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 rvalues. Some unary expressions change the type:

>>> type(-True)
<class 'int'>

Copy link
Member

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 :)

Copy link
Member Author

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

@sobolevn
Copy link
Member Author

sobolevn commented Jul 13, 2023

Now I only allow a very small subset of unary expressions. But, ones I allow make a lot of sense and are very common.

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@sobolevn
Copy link
Member Author

Failures are unrelated, see #15657
I will merge it once #15659 is merged.

@sobolevn sobolevn merged commit 2ebd51e into master Jul 13, 2023
@sobolevn sobolevn deleted the stubgen-complex branch July 13, 2023 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants