Skip to content

Commit 40a04d8

Browse files
authored
Adds Final types where they were missing (#11278)
I've noticed several missing Final types here and there. I've looked though the whole project and added them where appropriate.
1 parent 32448b8 commit 40a04d8

File tree

7 files changed

+20
-18
lines changed

7 files changed

+20
-18
lines changed

mypy/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
DEBUG_FINE_GRAINED: Final = False
7070

7171
# These modules are special and should always come from typeshed.
72-
CORE_BUILTIN_MODULES = {
72+
CORE_BUILTIN_MODULES: Final = {
7373
'builtins',
7474
'typing',
7575
'types',

mypy/fastparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def ast3_parse(source: Union[str, bytes], filename: str, mode: str,
132132

133133
INVALID_SLICE_ERROR: Final = 'Slice usage in type annotation is invalid'
134134

135-
TYPE_IGNORE_PATTERN = re.compile(r'[^#]*#\s*type:\s*ignore\s*(.*)')
135+
TYPE_IGNORE_PATTERN: Final = re.compile(r'[^#]*#\s*type:\s*ignore\s*(.*)')
136136

137137

138138
def parse(source: Union[str, bytes],

mypy/plugins/functools.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
"""Plugin for supporting the functools standard library module."""
22
from typing import Dict, NamedTuple, Optional
3+
from typing_extensions import Final
34

45
import mypy.plugin
56
from mypy.nodes import ARG_POS, ARG_STAR2, Argument, FuncItem, Var
67
from mypy.plugins.common import add_method_to_class
78
from mypy.types import AnyType, CallableType, get_proper_type, Type, TypeOfAny, UnboundType
89

910

10-
functools_total_ordering_makers = {
11+
functools_total_ordering_makers: Final = {
1112
'functools.total_ordering',
1213
}
1314

14-
_ORDERING_METHODS = {
15+
_ORDERING_METHODS: Final = {
1516
'__lt__',
1617
'__le__',
1718
'__gt__',

mypy/plugins/singledispatch.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
('singledispatch_obj', Instance),
2323
])
2424

25-
SINGLEDISPATCH_TYPE = 'functools._SingleDispatchCallable'
25+
SINGLEDISPATCH_TYPE: Final = 'functools._SingleDispatchCallable'
2626

27-
SINGLEDISPATCH_REGISTER_METHOD = '{}.register'.format(SINGLEDISPATCH_TYPE) # type: Final
27+
SINGLEDISPATCH_REGISTER_METHOD: Final = '{}.register'.format(SINGLEDISPATCH_TYPE)
2828

29-
SINGLEDISPATCH_CALLABLE_CALL_METHOD = '{}.__call__'.format(SINGLEDISPATCH_TYPE) # type: Final
29+
SINGLEDISPATCH_CALLABLE_CALL_METHOD: Final = '{}.__call__'.format(SINGLEDISPATCH_TYPE)
3030

3131

3232
def get_singledispatch_info(typ: Instance) -> Optional[SingledispatchTypeVars]:
@@ -45,11 +45,11 @@ def get_first_arg(args: List[List[T]]) -> Optional[T]:
4545
return None
4646

4747

48-
REGISTER_RETURN_CLASS = '_SingleDispatchRegisterCallable'
48+
REGISTER_RETURN_CLASS: Final = '_SingleDispatchRegisterCallable'
4949

50-
REGISTER_CALLABLE_CALL_METHOD = 'functools.{}.__call__'.format(
50+
REGISTER_CALLABLE_CALL_METHOD: Final = 'functools.{}.__call__'.format(
5151
REGISTER_RETURN_CLASS
52-
) # type: Final
52+
)
5353

5454

5555
def make_fake_register_class_instance(api: CheckerPluginInterface, type_args: Sequence[Type]

mypy/semanal_main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"""
2626

2727
from typing import List, Tuple, Optional, Union, Callable
28-
from typing_extensions import TYPE_CHECKING
28+
from typing_extensions import TYPE_CHECKING, Final
2929

3030
from mypy.backports import nullcontext
3131
from mypy.nodes import (
@@ -55,12 +55,12 @@
5555

5656

5757
# If we perform this many iterations, raise an exception since we are likely stuck.
58-
MAX_ITERATIONS = 20
58+
MAX_ITERATIONS: Final = 20
5959

6060

6161
# Number of passes over core modules before going on to the rest of the builtin SCC.
62-
CORE_WARMUP = 2
63-
core_modules = ['typing', 'builtins', 'abc', 'collections']
62+
CORE_WARMUP: Final = 2
63+
core_modules: Final = ['typing', 'builtins', 'abc', 'collections']
6464

6565

6666
def semantic_analysis_for_scc(graph: 'Graph', scc: List[str], errors: Errors) -> None:

mypy/stubgenc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import re
1111
from typing import List, Dict, Tuple, Optional, Mapping, Any, Set
1212
from types import ModuleType
13+
from typing_extensions import Final
1314

1415
from mypy.moduleinspect import is_c_module
1516
from mypy.stubdoc import (
@@ -19,7 +20,7 @@
1920
)
2021

2122
# Members of the typing module to consider for importing by default.
22-
_DEFAULT_TYPING_IMPORTS = (
23+
_DEFAULT_TYPING_IMPORTS: Final = (
2324
'Any',
2425
'Callable',
2526
'ClassVar',

mypy/util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@
3030

3131
# At least this number of columns will be shown on each side of
3232
# error location when printing source code snippet.
33-
MINIMUM_WIDTH = 20
33+
MINIMUM_WIDTH: Final = 20
3434

3535
# VT100 color code processing was added in Windows 10, but only the second major update,
3636
# Threshold 2. Fortunately, everyone (even on LTSB, Long Term Support Branch) should
3737
# have a version of Windows 10 newer than this. Note that Windows 8 and below are not
3838
# supported, but are either going out of support, or make up only a few % of the market.
39-
MINIMUM_WINDOWS_MAJOR_VT100 = 10
40-
MINIMUM_WINDOWS_BUILD_VT100 = 10586
39+
MINIMUM_WINDOWS_MAJOR_VT100: Final = 10
40+
MINIMUM_WINDOWS_BUILD_VT100: Final = 10586
4141

4242
default_python2_interpreter: Final = [
4343
"python2",

0 commit comments

Comments
 (0)