mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Now overloads with ambiguous `self` are handled properly

Open sobolevn opened this issue 4 years ago • 8 comments

Closes #11347

sobolevn avatar Oct 20 '21 11:10 sobolevn

Diff from mypy_primer, showing the effect of this PR on open source code:

edgedb (https://github.com/edgedb/edgedb.git)
+ edb/schema/name.py:264:2: error: Untyped decorator makes function "_serialize_to_markup" untyped
+ edb/schema/objects.py:3209:2: error: Untyped decorator makes function "_serialize_to_markup" untyped
+ edb/schema/objects.py:3210:2: error: Untyped decorator makes function "_serialize_to_markup" untyped
+ edb/ir/ast.py:815:2: error: Untyped decorator makes function "_serialize_to_markup" untyped
- edb/ir/staeval.py:265:1: error: Dispatch type "TypeCast" must be subtype of fallback function first argument "ConstExpr"
+ edb/ir/staeval.py:205:2: error: Untyped decorator makes function "empty_set_to_python" untyped
+ edb/ir/staeval.py:213:2: error: Untyped decorator makes function "const_set_to_python" untyped
+ edb/ir/staeval.py:220:2: error: Untyped decorator makes function "int_const_to_python" untyped
+ edb/ir/staeval.py:234:2: error: Untyped decorator makes function "float_const_to_python" untyped
+ edb/ir/staeval.py:248:2: error: Untyped decorator makes function "str_const_to_python" untyped
+ edb/ir/staeval.py:256:2: error: Untyped decorator makes function "bool_const_to_python" untyped
+ edb/ir/staeval.py:264:2: error: Untyped decorator makes function "cast_const_to_python" untyped

tornado (https://github.com/tornadoweb/tornado.git)
- tornado/test/iostream_test.py:814: error: "IOLoop" has no attribute "selector_loop"

github-actions[bot] avatar Oct 20 '21 12:10 github-actions[bot]

Nice! It seems this PR fixes most of the issues. One case that does still seem to fail is when Foo[Any] subclasses are involved:

from typing import Generic, TypeVar, overload, Any

T = TypeVar('T')

class Some(Generic[T]):
    @overload
    def method(self: Some[int]) -> bool: ...
    @overload
    def method(self: Some[str]) -> float: ...
    def method(self): pass

class SomeSubtype(Some[Any]):
    pass

s3: Some[Any]
reveal_type(s3.method()) # N: Revealed type is "Any"

s4: SomeSubtype
reveal_type(s4.method())  # N: Revealed type is "builtins.bool"
# Should also be: Revealed type is "Any"

BvB93 avatar Oct 20 '21 13:10 BvB93

@BvB93 I think that this is unrelated. Because it would require a change in how has_any_type works. And it can backfire in lots of places. But, please open a new issue for it! 👍

sobolevn avatar Oct 20 '21 13:10 sobolevn

@BvB93 I think that this is unrelated. Because it would require a change in how has_any_type works. And it can backfire in lots of places. But, please open a new issue for it! 👍

That's fair; will do.

BvB93 avatar Oct 20 '21 20:10 BvB93

Out of curiosity, is there a particular reason why this has PR stalled?

BvB93 avatar Jul 01 '22 13:07 BvB93

Thanks for re-opening, but since I nuked my fork, I cannot edit or rebase this PR. I need to do it by hand via CLI. I will at some point!

sobolevn avatar Jul 28 '22 07:07 sobolevn

Thanks for re-opening, but since I nuked my fork, I cannot edit or rebase this PR. I need to do it by hand via CLI. I will at some point!

@sobolevn just wanted to hint that it's quite quickly to get hold the contents here in order to e.g. rebase. Should only be a few lines:

e.g.

git fetch origin pull/11366/head:issue-11347
git switch issue-11347
git rebase --onto origin/master 4d0ab445514e0f9795306c0bc88a202be209df6b issue-11347
...

Make sure to just swap out to your correct remote name and what branch name you'd like

Taken from: Modifying an inactive pull request locally

flaeppe avatar Apr 15 '24 10:04 flaeppe

@flaeppe feel free to take over this PR. I lost context of it :)

sobolevn avatar Apr 15 '24 16:04 sobolevn