Skip to content

Commit

Permalink
Use type instead of Type in errors on newer Python (#15139)
Browse files Browse the repository at this point in the history
Fixes #13027 (or at least half of it)
  • Loading branch information
rohitsanj committed Apr 26, 2023
1 parent 16b936c commit bf6b21d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2517,7 +2517,8 @@ def format_literal_value(typ: LiteralType) -> str:
else:
return "<nothing>"
elif isinstance(typ, TypeType):
return f"Type[{format(typ.item)}]"
type_name = "type" if options.use_lowercase_names() else "Type"
return f"{type_name}[{format(typ.item)}]"
elif isinstance(typ, FunctionLike):
func = typ
if func.is_type_obj():
Expand Down
7 changes: 7 additions & 0 deletions test-data/unit/check-lowercase.test
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,10 @@ x = 3 # E: Incompatible types in assignment (expression has type "int", variabl
x = {3}
x = 3 # E: Incompatible types in assignment (expression has type "int", variable has type "set[int]")
[builtins fixtures/set.pyi]

[case testTypeLowercaseSettingOff]
# flags: --python-version 3.9 --no-force-uppercase-builtins
x: type[type]
y: int

y = x # E: Incompatible types in assignment (expression has type "type[type]", variable has type "int")

0 comments on commit bf6b21d

Please sign in to comment.