Skip to content

Commit 11576c4

Browse files
committed
Adjust first arg logic accordingly
1 parent 57bc518 commit 11576c4

10 files changed

Lines changed: 25 additions & 23 deletions

mypy/messages.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3051,6 +3051,8 @@ def [T <: int] f(self, x: int, y: T) -> None
30513051
# TODO: avoid different logic for incremental runs.
30523052
first_arg = get_first_arg(tp)
30533053

3054+
if tp.is_type_obj():
3055+
skip_self = True
30543056
if first_arg and not skip_self:
30553057
if s:
30563058
s = ", " + s

test-data/unit/check-classes.test

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3492,8 +3492,8 @@ c.a # E: "C" has no attribute "a"
34923492
C('', '')
34933493
C('') # E: No overload variant of "C" matches argument type "str" \
34943494
# N: Possible overload variants: \
3495-
# N: def C(cls, foo: int) -> C \
3496-
# N: def C(cls, x: str, y: str) -> C
3495+
# N: def C(foo: int) -> C \
3496+
# N: def C(x: str, y: str) -> C
34973497
[builtins fixtures/__new__.pyi]
34983498

34993499

@@ -3922,8 +3922,8 @@ u = new(User)
39223922
[out]
39233923
tmp/foo.pyi:17: error: No overload variant of "User" matches argument type "str"
39243924
tmp/foo.pyi:17: note: Possible overload variants:
3925-
tmp/foo.pyi:17: note: def User(self) -> U
3926-
tmp/foo.pyi:17: note: def User(self, arg: int) -> U
3925+
tmp/foo.pyi:17: note: def User() -> U
3926+
tmp/foo.pyi:17: note: def User(arg: int) -> U
39273927
tmp/foo.pyi:18: error: Too many arguments for "foo" of "User"
39283928

39293929
[case testTypeUsingTypeCInUpperBound]
@@ -8517,7 +8517,7 @@ class Child(Parent):
85178517
return val
85188518
def bar(self, val: str) -> str: # E: Signature of "bar" incompatible with supertype "Parent" \
85198519
# N: Superclass: \
8520-
# N: def bar(self) -> bar \
8520+
# N: def bar() -> bar \
85218521
# N: Subclass: \
85228522
# N: def bar(self, val: str) -> str
85238523
return val

test-data/unit/check-flags.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2483,13 +2483,13 @@ cb(fn)
24832483
x: int = "" # E: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment]
24842484
list(1) # E: No overload variant of "list" matches argument type "int" [call-overload] \
24852485
# N: Possible overload variants: \
2486-
# N: def [T] list(self) -> list[T] \
2487-
# N: def [T] list(self, x: Iterable[T]) -> list[T] \
2486+
# N: def [T] list() -> list[T] \
2487+
# N: def [T] list(x: Iterable[T]) -> list[T] \
24882488
# N: See https://mypy.rtfd.io/en/stable/_refs.html#code-call-overload for more info
24892489
list(2) # E: No overload variant of "list" matches argument type "int" [call-overload] \
24902490
# N: Possible overload variants: \
2491-
# N: def [T] list(self) -> list[T] \
2492-
# N: def [T] list(self, x: Iterable[T]) -> list[T]
2491+
# N: def [T] list() -> list[T] \
2492+
# N: def [T] list(x: Iterable[T]) -> list[T]
24932493
[builtins fixtures/list.pyi]
24942494

24952495
[case testNestedGenericInAliasDisallow]

test-data/unit/check-inference.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,8 +1753,8 @@ def f(blocks: object):
17531753
to_process = []
17541754
to_process = list(blocks) # E: No overload variant of "list" matches argument type "object" \
17551755
# N: Possible overload variants: \
1756-
# N: def [T] list(self) -> list[T] \
1757-
# N: def [T] list(self, x: Iterable[T]) -> list[T]
1756+
# N: def [T] list() -> list[T] \
1757+
# N: def [T] list(x: Iterable[T]) -> list[T]
17581758
[builtins fixtures/list.pyi]
17591759

17601760
[case testInferListInitializedToEmptyAndAssigned]

test-data/unit/check-overloading.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,8 @@ a = A(a)
625625
a = A(b)
626626
a = A(object()) # E: No overload variant of "A" matches argument type "object" \
627627
# N: Possible overload variants: \
628-
# N: def A(self, a: A) -> A \
629-
# N: def A(self, b: B) -> A
628+
# N: def A(a: A) -> A \
629+
# N: def A(b: B) -> A
630630

631631
class A:
632632
@overload

test-data/unit/check-python311.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ myclass2 = MyClass(float, float)
137137
reveal_type(myclass2) # N: Revealed type is "__main__.MyClass[builtins.float, builtins.float]"
138138
myclass3 = MyClass(float, float, float) # E: No overload variant of "MyClass" matches argument types "type[float]", "type[float]", "type[float]" \
139139
# N: Possible overload variants: \
140-
# N: def [T1, T2] MyClass(self) -> MyClass[None, None] \
141-
# N: def [T1, T2] MyClass(self, type[T1], /) -> MyClass[T1, None] \
140+
# N: def [T1, T2] MyClass() -> MyClass[None, None] \
141+
# N: def [T1, T2] MyClass(type[T1], /) -> MyClass[T1, None] \
142142
# N: def [T1, T2] MyClass(type[T1], type[T2], /) -> MyClass[T1, T2]
143143
reveal_type(myclass3) # N: Revealed type is "Any"
144144
[builtins fixtures/tuple.pyi]

test-data/unit/check-selftype.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,8 +767,8 @@ class SubP(P[T]):
767767

768768
SubP('no') # E: No overload variant of "SubP" matches argument type "str" \
769769
# N: Possible overload variants: \
770-
# N: def [T] SubP(self, use_str: Literal[True]) -> SubP[T] \
771-
# N: def [T] SubP(self, use_str: Literal[False]) -> SubP[T]
770+
# N: def [T] SubP(use_str: Literal[True]) -> SubP[T] \
771+
# N: def [T] SubP(use_str: Literal[False]) -> SubP[T]
772772

773773
# This is a bit unfortunate: we don't have a way to map the overloaded __init__ to subtype.
774774
x = SubP(use_str=True) # E: Need type annotation for "x"

test-data/unit/check-serialize.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ class A:
312312
[out2]
313313
tmp/a.py:2: error: No overload variant of "A" matches argument type "object"
314314
tmp/a.py:2: note: Possible overload variants:
315-
tmp/a.py:2: note: def A(self, x: int) -> A
316-
tmp/a.py:2: note: def A(self, x: str) -> A
315+
tmp/a.py:2: note: def A(x: int) -> A
316+
tmp/a.py:2: note: def A(x: str) -> A
317317
tmp/a.py:7: error: No overload variant of "__init__" of "A" matches argument type "object"
318318
tmp/a.py:7: note: Possible overload variants:
319319
tmp/a.py:7: note: def __init__(self, x: int) -> None

test-data/unit/check-type-aliases.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,8 +1347,8 @@ reveal_type(D()) # N: Revealed type is "builtins.dict[builtins.str, builtins.in
13471347
reveal_type(D(x=1)) # N: Revealed type is "builtins.dict[builtins.str, builtins.int]"
13481348
reveal_type(D(x="asdf")) # E: No overload variant of "dict" matches argument type "str" \
13491349
# N: Possible overload variants: \
1350-
# N: def dict(self, **kwargs: int) -> dict[str, int] \
1351-
# N: def dict(self, arg: Iterable[tuple[str, int]], **kwargs: int) -> dict[str, int] \
1350+
# N: def dict(**kwargs: int) -> dict[str, int] \
1351+
# N: def dict(arg: Iterable[tuple[str, int]], **kwargs: int) -> dict[str, int] \
13521352
# N: Revealed type is "Any"
13531353
[builtins fixtures/dict.pyi]
13541354

test-data/unit/fine-grained.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7381,8 +7381,8 @@ class C:
73817381
==
73827382
a.py:2: error: No overload variant of "B" matches argument type "int"
73837383
a.py:2: note: Possible overload variants:
7384-
a.py:2: note: def B(self, x: str) -> B
7385-
a.py:2: note: def B(self, x: str, y: int) -> B
7384+
a.py:2: note: def B(x: str) -> B
7385+
a.py:2: note: def B(x: str, y: int) -> B
73867386

73877387
[case testOverloadedToNormalMethodMetaclass]
73887388
import a

0 commit comments

Comments
 (0)