Skip to content

Fix incorrect type inference for inherited from Any class - #8019

Merged
msullivan merged 5 commits into
python:masterfrom
TH3CHARLie:fix-false-positive-multiply-float-with-Any
Dec 13, 2019
Merged

msullivan merged 5 commits into
python:masterfrom
TH3CHARLie:fix-false-positive-multiply-float-with-Any

Conversation

@TH3CHARLie

@TH3CHARLie TH3CHARLie commented Nov 27, 2019 •

Copy link
Copy Markdown
Collaborator

resolves #8001

Comment thread mypy/checkexpr.py Outdated
@TH3CHARLie TH3CHARLie changed the title Fix incorrect type analysis for inherited from Any class Fix incorrect type inference for inherited from Any class Dec 2, 2019

@msullivan msullivan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This looks good to me. I'll merge it tomorrow unless @ilevkivskyi or @Michael0x2a have more feedback

Comment thread mypy/checkexpr.py
# if so, we also return Any
if ((isinstance(left_type, Instance) and left_type.type.fallback_to_any) or
(isinstance(right_type, Instance) and right_type.type.fallback_to_any)):
any_type = AnyType(TypeOfAny.special_form)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm not sure if special_form is the right thing here but I'm not totally sure what else to do. from_another_any is correct but digging out the other any is almost certainly not worth bothering.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I am also not sure about whether special_form is the right thing to go, but clearly directly using from_another_any with either left_type or right_type here is incorrect. To proper use from_another_any, we need a better way to transform the Instance to an Any

@msullivan

Copy link
Copy Markdown
Collaborator

Oh, I guess please fix the merge conflict

@TH3CHARLie

Copy link
Copy Markdown
Collaborator Author

Oh, I guess please fix the merge conflict

fixed

@msullivan
msullivan merged commit 8a08e78 into python:master Dec 13, 2019
@TH3CHARLie
TH3CHARLie deleted the fix-false-positive-multiply-float-with-Any branch December 14, 2019 02:32
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.

Float multiplication of numpy.ndarray in lambda is incorrectly analysed

4 participants