Skip to content

Commit 98d59a2

Browse files
committed
Deprecated --force-uppercase-builtins flag
1 parent 409d294 commit 98d59a2

File tree

6 files changed

+33
-65
lines changed

6 files changed

+33
-65
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Next Release
44

5+
### Deprecated Flag: \--force-uppercase-builtins
6+
7+
Mypy only supports Python 3.9+. The \--force-uppercase-builtins flag is now deprecated and a no-op. It will be removed in a future version.
8+
59
## Mypy 1.16
610

711
We’ve just uploaded mypy 1.16 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)).

mypy/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,7 @@ def add_invertible_flag(
801801
help="Disable strict Optional checks (inverse: --strict-optional)",
802802
)
803803

804+
# This flag is deprecated, Mypy only supports Python 3.9+
804805
add_invertible_flag(
805806
"--force-uppercase-builtins", default=False, help=argparse.SUPPRESS, group=none_group
806807
)
@@ -1494,6 +1495,9 @@ def set_strict_flags() -> None:
14941495
if options.strict_concatenate and not strict_option_set:
14951496
print("Warning: --strict-concatenate is deprecated; use --extra-checks instead")
14961497

1498+
if options.force_uppercase_builtins:
1499+
print("Warning: --force-uppercase-builtins is deprecated; Mypy only supports Python 3.9+.")
1500+
14971501
# Set target.
14981502
if special_opts.modules + special_opts.packages:
14991503
options.build_type = BuildType.MODULE

mypy/messages.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,13 +1823,10 @@ def need_annotation_for_var(
18231823
recommended_type = f"Optional[{type_dec}]"
18241824
elif node.type.type.fullname in reverse_builtin_aliases:
18251825
# partial types other than partial None
1826-
alias = reverse_builtin_aliases[node.type.type.fullname]
1827-
alias = alias.split(".")[-1]
1828-
if alias == "Dict":
1826+
name = node.type.type.fullname.partition(".")[2]
1827+
if name == "dict":
18291828
type_dec = f"{type_dec}, {type_dec}"
1830-
if self.options.use_lowercase_names():
1831-
alias = alias.lower()
1832-
recommended_type = f"{alias}[{type_dec}]"
1829+
recommended_type = f"{name}[{type_dec}]"
18331830
if recommended_type is not None:
18341831
hint = f' (hint: "{node.name}: {recommended_type} = ...")'
18351832

@@ -2419,8 +2416,7 @@ def format_long_tuple_type(self, typ: TupleType) -> str:
24192416
"""Format very long tuple type using an ellipsis notation"""
24202417
item_cnt = len(typ.items)
24212418
if item_cnt > MAX_TUPLE_ITEMS:
2422-
return "{}[{}, {}, ... <{} more items>]".format(
2423-
"tuple" if self.options.use_lowercase_names() else "Tuple",
2419+
return "tuple[{}, {}, ... <{} more items>]".format(
24242420
format_type_bare(typ.items[0], self.options),
24252421
format_type_bare(typ.items[1], self.options),
24262422
str(item_cnt - 2),
@@ -2595,10 +2591,7 @@ def format_literal_value(typ: LiteralType) -> str:
25952591
if itype.type.fullname == "typing._SpecialForm":
25962592
# This is not a real type but used for some typing-related constructs.
25972593
return "<typing special form>"
2598-
if itype.type.fullname in reverse_builtin_aliases and not options.use_lowercase_names():
2599-
alias = reverse_builtin_aliases[itype.type.fullname]
2600-
base_str = alias.split(".")[-1]
2601-
elif verbosity >= 2 or (fullnames and itype.type.fullname in fullnames):
2594+
if verbosity >= 2 or (fullnames and itype.type.fullname in fullnames):
26022595
base_str = itype.type.fullname
26032596
else:
26042597
base_str = itype.type.name
@@ -2609,7 +2602,7 @@ def format_literal_value(typ: LiteralType) -> str:
26092602
return base_str
26102603
elif itype.type.fullname == "builtins.tuple":
26112604
item_type_str = format(itype.args[0])
2612-
return f"{'tuple' if options.use_lowercase_names() else 'Tuple'}[{item_type_str}, ...]"
2605+
return f"tuple[{item_type_str}, ...]"
26132606
else:
26142607
# There are type arguments. Convert the arguments to strings.
26152608
return f"{base_str}[{format_list(itype.args)}]"
@@ -2645,11 +2638,7 @@ def format_literal_value(typ: LiteralType) -> str:
26452638
if typ.partial_fallback.type.fullname != "builtins.tuple":
26462639
return format(typ.partial_fallback)
26472640
type_items = format_list(typ.items) or "()"
2648-
if options.use_lowercase_names():
2649-
s = f"tuple[{type_items}]"
2650-
else:
2651-
s = f"Tuple[{type_items}]"
2652-
return s
2641+
return f"tuple[{type_items}]"
26532642
elif isinstance(typ, TypedDictType):
26542643
# If the TypedDictType is named, return the name
26552644
if not typ.is_anonymous():
@@ -2721,8 +2710,7 @@ def format_literal_value(typ: LiteralType) -> str:
27212710
elif isinstance(typ, UninhabitedType):
27222711
return "Never"
27232712
elif isinstance(typ, TypeType):
2724-
type_name = "type" if options.use_lowercase_names() else "Type"
2725-
return f"{type_name}[{format(typ.item)}]"
2713+
return f"type[{format(typ.item)}]"
27262714
elif isinstance(typ, FunctionLike):
27272715
func = typ
27282716
if func.is_type_obj():

mypy/options.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import re
55
import sys
66
import sysconfig
7+
import warnings
78
from collections.abc import Mapping
89
from re import Pattern
910
from typing import Any, Callable, Final
@@ -400,6 +401,7 @@ def __init__(self) -> None:
400401

401402
self.disable_bytearray_promotion = False
402403
self.disable_memoryview_promotion = False
404+
# Deprecated, Mypy only supports Python 3.9+
403405
self.force_uppercase_builtins = False
404406
self.force_union_syntax = False
405407

@@ -413,6 +415,11 @@ def __init__(self) -> None:
413415
self.mypyc_skip_c_generation = False
414416

415417
def use_lowercase_names(self) -> bool:
418+
warnings.warn(
419+
"options.use_lowercase_names is deprecated and will be removed in a future version",
420+
DeprecationWarning,
421+
stacklevel=2,
422+
)
416423
if self.python_version >= (3, 9):
417424
return not self.force_uppercase_builtins
418425
return False

mypy/types.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3455,12 +3455,11 @@ def visit_overloaded(self, t: Overloaded, /) -> str:
34553455

34563456
def visit_tuple_type(self, t: TupleType, /) -> str:
34573457
s = self.list_str(t.items) or "()"
3458-
tuple_name = "tuple" if self.options.use_lowercase_names() else "Tuple"
34593458
if t.partial_fallback and t.partial_fallback.type:
34603459
fallback_name = t.partial_fallback.type.fullname
34613460
if fallback_name != "builtins.tuple":
3462-
return f"{tuple_name}[{s}, fallback={t.partial_fallback.accept(self)}]"
3463-
return f"{tuple_name}[{s}]"
3461+
return f"tuple[{s}, fallback={t.partial_fallback.accept(self)}]"
3462+
return f"tuple[{s}]"
34643463

34653464
def visit_typeddict_type(self, t: TypedDictType, /) -> str:
34663465
def item_str(name: str, typ: str) -> str:
@@ -3502,11 +3501,7 @@ def visit_ellipsis_type(self, t: EllipsisType, /) -> str:
35023501
return "..."
35033502

35043503
def visit_type_type(self, t: TypeType, /) -> str:
3505-
if self.options.use_lowercase_names():
3506-
type_name = "type"
3507-
else:
3508-
type_name = "Type"
3509-
return f"{type_name}[{t.item.accept(self)}]"
3504+
return f"type[{t.item.accept(self)}]"
35103505

35113506
def visit_placeholder_type(self, t: PlaceholderType, /) -> str:
35123507
return f"<placeholder {t.fullname}>"

test-data/unit/check-lowercase.test

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,34 @@
1-
2-
[case testTupleLowercaseSettingOff]
3-
# flags: --force-uppercase-builtins
4-
x = (3,)
5-
x = 3 # E: Incompatible types in assignment (expression has type "int", variable has type "Tuple[int]")
6-
[builtins fixtures/tuple.pyi]
7-
8-
[case testTupleLowercaseSettingOn]
9-
# flags: --no-force-uppercase-builtins
1+
[case testTupleLowercase]
102
x = (3,)
113
x = 3 # E: Incompatible types in assignment (expression has type "int", variable has type "tuple[int]")
124
[builtins fixtures/tuple.pyi]
135

14-
[case testListLowercaseSettingOff]
15-
# flags: --force-uppercase-builtins
16-
x = [3]
17-
x = 3 # E: Incompatible types in assignment (expression has type "int", variable has type "List[int]")
18-
19-
[case testListLowercaseSettingOn]
20-
# flags: --no-force-uppercase-builtins
6+
[case testListLowercase]
217
x = [3]
228
x = 3 # E: Incompatible types in assignment (expression has type "int", variable has type "list[int]")
239

24-
[case testDictLowercaseSettingOff]
25-
# flags: --force-uppercase-builtins
26-
x = {"key": "value"}
27-
x = 3 # E: Incompatible types in assignment (expression has type "int", variable has type "Dict[str, str]")
28-
29-
[case testDictLowercaseSettingOn]
30-
# flags: --no-force-uppercase-builtins
10+
[case testDictLowercase]
3111
x = {"key": "value"}
3212
x = 3 # E: Incompatible types in assignment (expression has type "int", variable has type "dict[str, str]")
3313

34-
[case testSetLowercaseSettingOff]
35-
# flags: --force-uppercase-builtins
36-
x = {3}
37-
x = 3 # E: Incompatible types in assignment (expression has type "int", variable has type "Set[int]")
38-
[builtins fixtures/set.pyi]
39-
40-
[case testSetLowercaseSettingOn]
41-
# flags: --no-force-uppercase-builtins
14+
[case testSetLowercase]
4215
x = {3}
4316
x = 3 # E: Incompatible types in assignment (expression has type "int", variable has type "set[int]")
4417
[builtins fixtures/set.pyi]
4518

46-
[case testTypeLowercaseSettingOff]
47-
# flags: --no-force-uppercase-builtins
19+
[case testTypeLowercase]
4820
x: type[type]
4921
y: int
5022

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

53-
[case testLowercaseSettingOnTypeAnnotationHint]
54-
# flags: --no-force-uppercase-builtins
25+
[case testLowercaseTypeAnnotationHint]
5526
x = [] # E: Need type annotation for "x" (hint: "x: list[<type>] = ...")
5627
y = {} # E: Need type annotation for "y" (hint: "y: dict[<type>, <type>] = ...")
5728
z = set() # E: Need type annotation for "z" (hint: "z: set[<type>] = ...")
5829
[builtins fixtures/primitives.pyi]
5930

60-
[case testLowercaseSettingOnRevealTypeType]
61-
# flags: --no-force-uppercase-builtins
31+
[case testLowercaseRevealTypeType]
6232
def f(t: type[int]) -> None:
6333
reveal_type(t) # N: Revealed type is "type[builtins.int]"
6434
reveal_type(f) # N: Revealed type is "def (t: type[builtins.int])"

0 commit comments

Comments
 (0)