Skip to content

Commit bf6b21d

Browse files
authored
Use type instead of Type in errors on newer Python (#15139)
Fixes #13027 (or at least half of it)
1 parent 16b936c commit bf6b21d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

mypy/messages.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2517,7 +2517,8 @@ def format_literal_value(typ: LiteralType) -> str:
25172517
else:
25182518
return "<nothing>"
25192519
elif isinstance(typ, TypeType):
2520-
return f"Type[{format(typ.item)}]"
2520+
type_name = "type" if options.use_lowercase_names() else "Type"
2521+
return f"{type_name}[{format(typ.item)}]"
25212522
elif isinstance(typ, FunctionLike):
25222523
func = typ
25232524
if func.is_type_obj():

test-data/unit/check-lowercase.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,10 @@ x = 3 # E: Incompatible types in assignment (expression has type "int", variabl
4242
x = {3}
4343
x = 3 # E: Incompatible types in assignment (expression has type "int", variable has type "set[int]")
4444
[builtins fixtures/set.pyi]
45+
46+
[case testTypeLowercaseSettingOff]
47+
# flags: --python-version 3.9 --no-force-uppercase-builtins
48+
x: type[type]
49+
y: int
50+
51+
y = x # E: Incompatible types in assignment (expression has type "type[type]", variable has type "int")

0 commit comments

Comments
 (0)