8000 Remove force_uppercase_builtins default from test helpers by cdce8p · Pull Request #19173 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Remove force_uppercase_builtins default from test helpers #19173

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

Merged
merged 4 commits into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update all other test cases
  • Loading branch information
cdce8p committed May 30, 2025
commit 2d53523e10ce6de5c8352f11a77150b591f382f5
18 changes: 9 additions & 9 deletions test-data/unit/check-abstract.test
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ def f(cls: Type[A]) -> A:
def g() -> A:
return A() # E: Cannot instantiate abstract class "A" with abstract attribute "m"

f(A) # E: Only concrete class can be given where "Type[A]" is expected
f(B) # E: Only concrete class can be given where "Type[A]" is expected
f(A) # E: Only concrete class can be given where "type[A]" is expected
f(B) # E: Only concrete class can be given where "type[A]" is expected
f(C) # OK
x: Type[B]
f(x) # OK
Expand All @@ -207,7 +207,7 @@ class Class:
def method(self) -> None:
pass

my_dict_init: Dict[int, Type[Class]] = {0: Class} # E: Only concrete class can be given where "Tuple[int, Type[Class]]" is expected
my_dict_init: Dict[int, Type[Class]] = {0: Class} # E: Only concrete class can be given where "tuple[int, type[Class]]" is expected

class Child(Class):
def method(self) -> None: ...
Expand Down Expand Up @@ -235,7 +235,7 @@ Alias = A
GoodAlias = C
Alias() # E: Cannot instantiate abstract class "A" with abstract attribute "m"
GoodAlias()
f(Alias) # E: Only concrete class can be given where "Type[A]" is expected
f(Alias) # E: Only concrete class can be given where "type[A]" is expected
f(GoodAlias)
[out]

Expand All @@ -255,18 +255,18 @@ class C(B):
var: Type[A]
var()
if int():
var = A # E: Can only assign concrete classes to a variable of type "Type[A]"
var = A # E: Can only assign concrete classes to a variable of type "type[A]"
if int():
var = B # E: Can only assign concrete classes to a variable of type "Type[A]"
var = B # E: Can only assign concrete classes to a variable of type "type[A]"
if int():
var = C # OK

var_old = None # type: Type[A] # Old syntax for variable annotations
var_old()
if int():
var_old = A # E: Can only assign concrete classes to a variable of type "Type[A]"
var_old = A # E: Can only assign concrete classes to a variable of type "type[A]"
if int():
var_old = B # E: Can only assign concrete classes to a variable of type "Type[A]"
var_old = B # E: Can only assign concrete classes to a variable of type "type[A]"
if int():
var_old = C # OK

Expand All @@ -277,7 +277,7 @@ class D(A):
def __new__(cls) -> "D": ...
def __new__(cls, a=None) -> "D": ...
if int():
var = D # E: Can only assign concrete classes to a variable of type "Type[A]"
var = D # E: Can only assign concrete classes to a variable of type "type[A]"
[out]

[case testInstantiationAbstractsInTypeForClassMethods]
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-annotated.test
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ from typing_extensions import Annotated
T = TypeVar('T')
Alias = Annotated[Tuple[T, T], ...]
x: Alias[int]
reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.int]"
reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.int]"
[builtins fixtures/tuple.pyi]

[case testAnnotatedAliasGenericUnion]
Expand Down
10 changes: 5 additions & 5 deletions test-data/unit/check-async-await.test
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ async def f() -> None:
[builtins fixtures/async_await.pyi]
[typing fixtures/typing-async.pyi]
[out]
main:4: error: "List[int]" has no attribute "__aiter__" (not async iterable)
main:4: error: "list[int]" has no attribute "__aiter__" (not async iterable)

[case testAsyncForErrorNote]

Expand Down Expand Up @@ -502,7 +502,7 @@ async def gen() -> AsyncGenerator[int, str]:

async def h() -> None:
g = gen()
await g.asend(()) # E: Argument 1 to "asend" of "AsyncGenerator" has incompatible type "Tuple[()]"; expected "str"
await g.asend(()) # E: Argument 1 to "asend" of "AsyncGenerator" has incompatible type "tuple[()]"; expected "str"
reveal_type(await g.asend('hello')) # N: Revealed type is "builtins.int"

[builtins fixtures/dict.pyi]
Expand Down Expand Up @@ -913,9 +913,9 @@ async def test(x: Sub[D], tx: Type[Sub[D]]) -> None:
unknown2: Awaitable[Any]
d: C = unknown2 # E: Incompatible types in assignment (expression has type "Awaitable[Any]", variable has type "C")

# The notes are not show for Type[...] (because awaiting them will not work)
tx.x # E: "Type[Sub[D]]" has no attribute "x"
a2: C = tx # E: Incompatible types in assignment (expression has type "Type[Sub[D]]", variable has type "C")
# The notes are not show for type[...] (because awaiting them will not work)
tx.x # E: "type[Sub[D]]" has no attribute "x"
a2: C = tx # E: Incompatible types in assignment (expression has type "type[Sub[D]]", variable has type "C")

class F:
def __await__(self: T) -> Generator[Any, Any, T]: ...
Expand Down
24 changes: 12 additions & 12 deletions test-data/unit/check-basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ reveal_type(b) # N: Revealed type is "Literal[False]"
from typing import List
x: List[int]
y: List[float]
y = x # E: Incompatible types in assignment (expression has type "List[int]", variable has type "List[float]") \
y = x # E: Incompatible types in assignment (expression has type "list[int]", variable has type "list[float]") \
# N: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
# N: Consider using "Sequence" instead, which is covariant
[builtins fixtures/list.pyi]
Expand All @@ -387,7 +387,7 @@ y = x # E: Incompatible types in assignment (expression has type "List[int]", va
from typing import Dict
x: Dict[str, int]
y: Dict[str, float]
y = x # E: Incompatible types in assignment (expression has type "Dict[str, int]", variable has type "Dict[str, float]") \
y = x # E: Incompatible types in assignment (expression has type "dict[str, int]", variable has type "dict[str, float]") \
# N: "dict" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
# N: Consider using "Mapping" instead, which is covariant in the value type
[builtins fixtures/dict.pyi]
Expand Down Expand Up @@ -420,7 +420,7 @@ def foo() -> Optional[A]:

def bar() -> List[A]:
l = [a.A()]
return l # E: Incompatible return value type (got "List[a.A]", expected "List[b.A]")
return l # E: Incompatible return value type (got "list[a.A]", expected "list[b.A]")

def baz() -> Union[A, int]:
b = True
Expand All @@ -431,37 +431,37 @@ def spam() -> Optional[A]:

def eggs() -> Sequence[A]:
x = [a.A()]
return x # E: Incompatible return value type (got "List[a.A]", expected "Sequence[b.A]")
return x # E: Incompatible return value type (got "list[a.A]", expected "Sequence[b.A]")

def eggs2() -> Sequence[N]:
x = [a.N(0)]
return x # E: Incompatible return value type (got "List[a.N]", expected "Sequence[b.N]")
return x # E: Incompatible return value type (got "list[a.N]", expected "Sequence[b.N]")

def asdf1() -> Sequence[Tuple[a.A, A]]:
x = [(a.A(), a.A())]
return x # E: Incompatible return value type (got "List[Tuple[a.A, a.A]]", expected "Sequence[Tuple[a.A, b.A]]")
return x # E: Incompatible return value type (got "list[tuple[a.A, a.A]]", expected "Sequence[tuple[a.A, b.A]]")

def asdf2() -> Sequence[Tuple[A, a.A]]:
x = [(a.A(), a.A())]
return x # E: Incompatible return value type (got "List[Tuple[a.A, a.A]]", expected "Sequence[Tuple[b.A, a.A]]")
return x # E: Incompatible return value type (got "list[tuple[a.A, a.A]]", expected "Sequence[tuple[b.A, a.A]]")

def arg() -> Tuple[A, A]:
return A() # E: Incompatible return value type (got "A", expected "Tuple[A, A]")
return A() # E: Incompatible return value type (got "A", expected "tuple[A, A]")

def types() -> Sequence[Type[A]]:
x = [a.A]
return x # E: Incompatible return value type (got "List[Type[a.A]]", expected "Sequence[Type[b.A]]")
return x # E: Incompatible return value type (got "list[type[a.A]]", expected "Sequence[type[b.A]]")

def literal() -> Sequence[Literal[B.b]]:
x = [a.B.b] # type: List[Literal[a.B.b]]
return x # E: Incompatible return value type (got "List[Literal[a.B.b]]", expected "Sequence[Literal[b.B.b]]")
return x # E: Incompatible return value type (got "list[Literal[a.B.b]]", expected "Sequence[Literal[b.B.b]]")

def typeddict() -> Sequence[D]:
x = [{'x': 0}] # type: List[a.D]
return x # E: Incompatible return value type (got "List[a.D]", expected "Sequence[b.D]")
return x # E: Incompatible return value type (got "list[a.D]", expected "Sequence[b.D]")

a = (a.A(), A())
a.x # E: "Tuple[a.A, b.A]" has no attribute "x"
a.x # E: "tuple[a.A, b.A]" has no attribute "x"
[builtins fixtures/dict.pyi]
[typing fixtures/typing-full.pyi]

Expand Down
52 changes: 26 additions & 26 deletions test-data/unit/check-class-namedtuple.test
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ t: Tuple[int, str]
if int():
b = a # E: Incompatible types in assignment (expression has type "A", variable has type "B")
if int():
a = t # E: Incompatible types in assignment (expression has type "Tuple[int, str]", variable has type "A")
a = t # E: Incompatible types in assignment (expression has type "tuple[int, str]", variable has type "A")
if int():
b = t # E: Incompatible types in assignment (expression has type "Tuple[int, str]", variable has type "B")
b = t # E: Incompatible types in assignment (expression has type "tuple[int, str]", variable has type "B")
if int():
t = a
if int():
Expand All @@ -212,7 +212,7 @@ a = l[0]
(i,) = l[0]
i, i = l[0] # E: Need more than 1 value to unpack (2 expected)
l = [A(1)]
a = (1,) # E: Incompatible types in assignment (expression has type "Tuple[int]", \
a = (1,) # E: Incompatible types in assignment (expression has type "tuple[int]", \
variable has type "A")
[builtins fixtures/list.pyi]

Expand All @@ -223,7 +223,7 @@ class MyNamedTuple(NamedTuple):
a: int
b: str

MyNamedTuple.x # E: "Type[MyNamedTuple]" has no attribute "x"
MyNamedTuple.x # E: "type[MyNamedTuple]" has no attribute "x"
[builtins fixtures/tuple.pyi]

[case testNewNamedTupleEmptyItems]
Expand Down Expand Up @@ -281,7 +281,7 @@ class X(NamedTuple):
y: str

x: X
reveal_type(x._replace()) # N: Revealed type is "Tuple[builtins.int, builtins.str, fallback=__main__.X]"
reveal_type(x._replace()) # N: Revealed type is "tuple[builtins.int, builtins.str, fallback=__main__.X]"
x._replace(x=5)
x._replace(y=5) # E: Argument "y" to "_replace" of "X" has incompatible type "int"; expected "str"
[builtins fixtures/tuple.pyi]
Expand All @@ -293,7 +293,7 @@ class X(NamedTuple):
x: int
y: str

reveal_type(X._fields) # N: Revealed type is "Tuple[builtins.str, builtins.str]"
reveal_type(X._fields) # N: Revealed type is "tuple[builtins.str, builtins.str]"
reveal_type(X._field_types) # N: Revealed type is "builtins.dict[builtins.str, Any]"
reveal_type(X._field_defaults) # N: Revealed type is "builtins.dict[builtins.str, Any]"

Expand Down Expand Up @@ -324,7 +324,7 @@ class Y(NamedTuple):
x: int
y: str

reveal_type([X(3, 'b'), Y(1, 'a')]) # N: Revealed type is "builtins.list[Tuple[builtins.int, builtins.str]]"
reveal_type([X(3, 'b'), Y(1, 'a')]) # N: Revealed type is "builtins.list[tuple[builtins.int, builtins.str]]"

[builtins fixtures/list.pyi]

Expand All @@ -335,8 +335,8 @@ class X(NamedTuple):
x: int
y: str

reveal_type([(3, 'b'), X(1, 'a')]) # N: Revealed type is "builtins.list[Tuple[builtins.int, builtins.str]]"
reveal_type([X(1, 'a'), (3, 'b')]) # N: Revealed type is "builtins.list[Tuple[builtins.int, builtins.str]]"
reveal_type([(3, 'b'), X(1, 'a')]) # N: Revealed type is "builtins.list[tuple[builtins.int, builtins.str]]"
reveal_type([X(1, 'a'), (3, 'b')]) # N: Revealed type is "builtins.list[tuple[builtins.int, builtins.str]]"

[builtins fixtures/list.pyi]

Expand Down Expand Up @@ -386,8 +386,8 @@ class X(NamedTuple):
x: int
y: int = 2

reveal_type(X(1)) # N: Revealed type is "Tuple[builtins.int, builtins.int, fallback=__main__.X]"
reveal_type(X(1, 2)) # N: Revealed type is "Tuple[builtins.int, builtins.int, fallback=__main__.X]"
reveal_type(X(1)) # N: Revealed type is "tuple[builtins.int, builtins.int, fallback=__main__.X]"
reveal_type(X(1, 2)) # N: Revealed type is "tuple[builtins.int, builtins.int, fallback=__main__.X]"

X(1, 'a') # E: Argument 2 to "X" has incompatible type "str"; expected "int"
X(1, z=3) # E: Unexpected keyword argument "z" for "X"
Expand All @@ -396,14 +396,14 @@ class HasNone(NamedTuple):
x: int
y: Optional[int] = None

reveal_type(HasNone(1)) # N: Revealed type is "Tuple[builtins.int, Union[builtins.int, None], fallback=__main__.HasNone]"
reveal_type(HasNone(1)) # N: Revealed type is "tuple[builtins.int, Union[builtins.int, None], fallback=__main__.HasNone]"

class Parameterized(NamedTuple):
x: int
y: List[int] = [1] + [2]
z: List[int] = []

reveal_type(Parameterized(1)) # N: Revealed type is "Tuple[builtins.int, builtins.list[builtins.int], builtins.list[builtins.int], fallback=__main__.Parameterized]"
reveal_type(Parameterized(1)) # N: Revealed type is "tuple[builtins.int, builtins.list[builtins.int], builtins.list[builtins.int], fallback=__main__.Parameterized]"
Parameterized(1, ['not an int']) # E: List item 0 has incompatible type "str"; expected "int"

class Default:
Expand All @@ -412,8 +412,8 @@ class Default:
class UserDefined(NamedTuple):
x: Default = Default()

reveal_type(UserDefined()) # N: Revealed type is "Tuple[__main__.Default, fallback=__main__.UserDefined]"
reveal_type(UserDefined(Default())) # N: Revealed type is "Tuple[__main__.Default, fallback=__main__.UserDefined]"
reveal_type(UserDefined()) # N: Revealed type is "tuple[__main__.Default, fallback=__main__.UserDefined]"
reveal_type(UserDefined(Default())) # N: Revealed type is "tuple[__main__.Default, fallback=__main__.UserDefined]"
UserDefined(1) # E: Argument 1 to "UserDefined" has incompatible type "int"; expected "Default"

[builtins fixtures/list.pyi]
Expand All @@ -425,7 +425,7 @@ class HasNone(NamedTuple):
x: int
y: Optional[int] = None

reveal_type(HasNone(1)) # N: Revealed type is "Tuple[builtins.int, Union[builtins.int, None], fallback=__main__.HasNone]"
reveal_type(HasNone(1)) # N: Revealed type is "tuple[builtins.int, Union[builtins.int, None], fallback=__main__.HasNone]"
HasNone(None) # E: Argument 1 to "HasNone" has incompatible type "None"; expected "int"
HasNone(1, y=None)
HasNone(1, y=2)
Expand Down Expand Up @@ -463,7 +463,7 @@ class Y(X):
self.y
return self.x

reveal_type(Y('a')) # N: Revealed type is "Tuple[builtins.str, builtins.int, fallback=__main__.Y]"
reveal_type(Y('a')) # N: Revealed type is "tuple[builtins.str, builtins.int, fallback=__main__.Y]"
Y(y=1, x='1').method()

class CallsBaseInit(X):
Expand Down Expand Up @@ -511,7 +511,7 @@ class Overloader(NamedTuple):

reveal_type(Overloader(1).method('string')) # N: Revealed type is "builtins.str"
reveal_type(Overloader(1).method(1)) # N: Revealed type is "builtins.int"
Overloader(1).method(('tuple',)) # E: No overload variant of "method" of "Overloader" matches argument type "Tuple[str]" \
Overloader(1).method(('tuple',)) # E: No overload variant of "method" of "Overloader" matches argument type "tuple[str]" \
# N: Possible overload variants: \
# N: def method(self, y: str) -> str \
# N: def method(self, y: int) -> int
Expand All @@ -528,7 +528,7 @@ class Base(NamedTuple):
reveal_type(self) # N: Revealed type is "T`-1"
return self
def good_override(self) -> int:
reveal_type(self) # N: Revealed type is "Tuple[builtins.int, fallback=__main__.Base]"
reveal_type(self) # N: Revealed type is "tuple[builtins.int, fallback=__main__.Base]"
reveal_type(self[0]) # N: Revealed type is "builtins.int"
self[0] = 3 # E: Unsupported target for indexed assignment ("Base")
reveal_type(self.x) # N: Revealed type is "builtins.int"
Expand All @@ -538,14 +538,14 @@ class Base(NamedTuple):
# E: No overload variant of "__getitem__" of "tuple" matches argument type "TypeVar" \
# N: Possible overload variants: \
# N: def __getitem__(self, int, /) -> int \
# N: def __getitem__(self, slice, /) -> Tuple[int, ...]
# N: def __getitem__(self, slice, /) -> tuple[int, ...]
return self.x
def bad_override(self) -> int:
return self.x

class Child(Base):
def new_method(self) -> int:
reveal_type(self) # N: Revealed type is "Tuple[builtins.int, fallback=__main__.Child]"
reveal_type(self) # N: Revealed type is "tuple[builtins.int, fallback=__main__.Child]"
reveal_type(self[0]) # N: Revealed type is "builtins.int"
self[0] = 3 # E: Unsupported target for indexed assignment ("Child")
reveal_type(self.x) # N: Revealed type is "builtins.int"
Expand All @@ -560,8 +560,8 @@ class Child(Base):
def takes_base(base: Base) -> int:
return base.x

reveal_type(Base(1).copy()) # N: Revealed type is "Tuple[builtins.int, fallback=__main__.Base]"
reveal_type(Child(1).copy()) # N: Revealed type is "Tuple[builtins.int, fallback=__main__.Child]"
reveal_type(Base(1).copy()) # N: Revealed type is "tuple[builtins.int, fallback=__main__.Base]"
reveal_type(Child(1).copy()) # N: Revealed type is "tuple[builtins.int, fallback=__main__.Child]"
reveal_type(Base(1).good_override()) # N: Revealed type is "builtins.int"
reveal_type(Child(1).good_override()) # N: Revealed type is "builtins.int"
reveal_type(Base(1).bad_override()) # N: Revealed type is "builtins.int"
Expand Down Expand Up @@ -635,8 +635,8 @@ class HasClassMethod(NamedTuple):

@classmethod
def new(cls, f: str) -> 'HasClassMethod':
reveal_type(cls) # N: Revealed type is "Type[Tuple[builtins.str, fallback=__main__.HasClassMethod]]"
reveal_type(HasClassMethod) # N: Revealed type is "def (x: builtins.str) -> Tuple[builtins.str, fallback=__main__.HasClassMethod]"
reveal_type(cls) # N: Revealed type is "type[tuple[builtins.str, fallback=__main__.HasClassMethod]]"
reveal_type(HasClassMethod) # N: Revealed type is "def (x: builtins.str) -> tuple[builtins.str, fallback=__main__.HasClassMethod]"
return cls(x=f)

[builtins fixtures/classmethod.pyi]
Expand All @@ -661,7 +661,7 @@ class HasStaticMethod(NamedTuple):

@property
def size(self) -> int:
reveal_type(self) # N: Revealed type is "Tuple[builtins.str, fallback=__main__.HasStaticMethod]"
reveal_type(self) # N: Revealed type is "tuple[builtins.str, fallback=__main__.HasStaticMethod]"
return 4

[builtins fixtures/property.pyi]
Expand Down
Loading
0