Skip to content

Commit 6877d6f

Browse files
JukkaLilevkivskyi
andauthored
Make syntax of generic overload variants in messages close to PEP 695 (#17401)
We used a custom syntax for type variable bounds and restrictions. Use PEP 695 syntax instead (or at least something closer to PEP 695 syntax). Co-authored-by: Ivan Levkivskyi <[email protected]>
1 parent 7cb733a commit 6877d6f

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

mypy/messages.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2928,10 +2928,10 @@ def [T <: int] f(self, x: int, y: T) -> None
29282928
isinstance(upper_bound, Instance)
29292929
and upper_bound.type.fullname != "builtins.object"
29302930
):
2931-
tvars.append(f"{tvar.name} <: {format_type_bare(upper_bound, options)}")
2931+
tvars.append(f"{tvar.name}: {format_type_bare(upper_bound, options)}")
29322932
elif tvar.values:
29332933
tvars.append(
2934-
"{} in ({})".format(
2934+
"{}: ({})".format(
29352935
tvar.name,
29362936
", ".join([format_type_bare(tp, options) for tp in tvar.values]),
29372937
)

test-data/unit/check-generic-subtyping.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ main:14: error: Signature of "f" incompatible with supertype "A"
306306
main:14: note: Superclass:
307307
main:14: note: def [S] f(self, x: int, y: S) -> None
308308
main:14: note: Subclass:
309-
main:14: note: def [T1 <: str, S] f(self, x: T1, y: S) -> None
309+
main:14: note: def [T1: str, S] f(self, x: T1, y: S) -> None
310310

311311
-- Inheritance from generic types with implicit dynamic supertype
312312
-- --------------------------------------------------------------

test-data/unit/check-overloading.test

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,7 @@ f('x')() # E: "str" not callable
12761276
f(1)() # E: "bool" not callable
12771277
f(1.1) # E: No overload variant of "f" matches argument type "float" \
12781278
# N: Possible overload variants: \
1279-
# N: def [T <: str] f(x: T) -> T \
1279+
# N: def [T: str] f(x: T) -> T \
12801280
# N: def f(x: int) -> bool
12811281
f(mystr())() # E: "mystr" not callable
12821282
[builtins fixtures/primitives.pyi]
@@ -1298,8 +1298,8 @@ def g(x: U, y: V) -> None:
12981298
f(x)() # E: "mystr" not callable
12991299
f(y) # E: No overload variant of "f" matches argument type "V" \
13001300
# N: Possible overload variants: \
1301-
# N: def [T <: str] f(x: T) -> T \
1302-
# N: def [T <: str] f(x: List[T]) -> None
1301+
# N: def [T: str] f(x: T) -> T \
1302+
# N: def [T: str] f(x: List[T]) -> None
13031303
a = f([x])
13041304
reveal_type(a) # N: Revealed type is "None"
13051305
f([y]) # E: Value of type variable "T" of "f" cannot be "V"
@@ -1351,7 +1351,7 @@ f(b'1')() # E: "str" not callable
13511351
f(1.0) # E: No overload variant of "f" matches argument type "float" \
13521352
# N: Possible overload variants: \
13531353
# N: def f(x: int) -> int \
1354-
# N: def [AnyStr in (bytes, str)] f(x: AnyStr) -> str
1354+
# N: def [AnyStr: (bytes, str)] f(x: AnyStr) -> str
13551355

13561356
@overload
13571357
def g(x: AnyStr, *a: AnyStr) -> None: pass
@@ -4949,7 +4949,7 @@ x: Any
49494949
reveal_type(attr(x)) # N: Revealed type is "Any"
49504950
attr("hi", 1) # E: No overload variant of "attr" matches argument types "str", "int" \
49514951
# N: Possible overload variants: \
4952-
# N: def [T in (int, float)] attr(default: T, blah: int = ...) -> T \
4952+
# N: def [T: (int, float)] attr(default: T, blah: int = ...) -> T \
49534953
# N: def attr(default: Any = ...) -> int
49544954
[file lib.pyi]
49554955
from typing import overload, Any, TypeVar
@@ -4972,7 +4972,7 @@ x: Any
49724972
reveal_type(attr(x)) # N: Revealed type is "Any"
49734973
attr("hi", 1) # E: No overload variant of "attr" matches argument types "str", "int" \
49744974
# N: Possible overload variants: \
4975-
# N: def [T <: int] attr(default: T = ..., blah: int = ...) -> T \
4975+
# N: def [T: int] attr(default: T = ..., blah: int = ...) -> T \
49764976
# N: def attr(default: Any = ...) -> int
49774977
[file lib.pyi]
49784978
from typing import overload, TypeVar, Any

test-data/unit/check-protocols.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,7 +2182,7 @@ main:11: note: Following member(s) of "B" have conflicts:
21822182
main:11: note: Expected:
21832183
main:11: note: def [T] f(self, x: T) -> None
21842184
main:11: note: Got:
2185-
main:11: note: def [S <: int, T] f(self, x: S, y: T) -> None
2185+
main:11: note: def [S: int, T] f(self, x: S, y: T) -> None
21862186

21872187
[case testProtocolIncompatibilityWithGenericRestricted]
21882188
from typing import Protocol, TypeVar
@@ -2202,7 +2202,7 @@ main:11: note: Following member(s) of "B" have conflicts:
22022202
main:11: note: Expected:
22032203
main:11: note: def [T] f(self, x: T) -> None
22042204
main:11: note: Got:
2205-
main:11: note: def [S in (int, str), T] f(self, x: S, y: T) -> None
2205+
main:11: note: def [S: (int, str), T] f(self, x: S, y: T) -> None
22062206

22072207
[case testProtocolIncompatibilityWithManyOverloads]
22082208
from typing import Protocol, overload

test-data/unit/fine-grained.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7138,7 +7138,7 @@ T = TypeVar('T', bound=str)
71387138
a.py:2: error: No overload variant of "f" matches argument type "int"
71397139
a.py:2: note: Possible overload variants:
71407140
a.py:2: note: def f(x: C) -> None
7141-
a.py:2: note: def [c.T <: str] f(x: c.T) -> c.T
7141+
a.py:2: note: def [c.T: str] f(x: c.T) -> c.T
71427142

71437143
[case testOverloadsGenericToNonGeneric]
71447144
import a

0 commit comments

Comments
 (0)