8000 Use variable annotations (#10723) · python/mypy@f98f782 · GitHub
[go: up one dir, main page]

Skip to content

Commit f98f782

Browse files
authored
Use variable annotations (#10723)
* Run com2ann * manual fixes (mainly None defaults) * manual fixes (mainly stringifying types) * manual fixes (more default types) * and some type ignores * run darker to appease flake8 * fix tests part 1 of ??? * fix tests part 2 of ??? * fix tests part 3 of ??? * fix tests part 4 of ??? Co-authored-by: hauntsaninja <>
1 parent 9851cce commit f98f782

File tree

153 files changed

+2173
-2055
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+2173
-2055
lines changed

mypy/applytype.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def apply_generic_arguments(
7575
types = get_proper_types(orig_types)
7676

7777
# Create a map from type variable id to target type.
78-
id_to_type = {} # type: Dict[TypeVarId, Type]
78+
id_to_type: Dict[TypeVarId, Type] = {}
7979

8080
for tvar, type in zip(tvars, types):
8181
assert not isinstance(type, PartialType), "Internal error: must never apply partial type"

mypy/argmap.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ def map_actuals_to_formals(actual_kinds: List[int],
2323
argument type with the given index.
2424
"""
2525
nformals = len(formal_kinds)
26-
formal_to_actual = [[] for i in range(nformals)] # type: List[List[int]]
27-
ambiguous_actual_kwargs = [] # type: List[int]
26+
formal_to_actual: List[List[int]] = [[] for i in range(nformals)]
27+
ambiguous_actual_kwargs: List[int] = []
2828
fi = 0
2929
for ai, actual_kind in enumerate(actual_kinds):
3030
if actual_kind == nodes.ARG_POS:
@@ -112,7 +112,7 @@ def map_formals_to_actuals(actual_kinds: List[int],
112112
formal_names,
113113
actual_arg_type)
114114
# Now reverse the mapping.
115-
actual_to_formal = [[] for _ in actual_kinds] # type: List[List[int]]
115+
actual_to_formal: List[List[int]] = [[] for _ in actual_kinds]
116116
for formal, actuals in enumerate(formal_to_actual):
117117
for actual in actuals:
118118
actual_to_formal[actual].append(formal)
@@ -145,7 +145,7 @@ def __init__(self) -> None:
145145
# Next tuple *args index to use.
146146
self.tuple_index = 0
147147
# Keyword arguments in TypedDict **kwargs used.
148-
self.kwargs_used = set() # type: Set[str]
148+
self.kwargs_used: Set[str] = set()
149149

150150
def expand_actual_type(self,
151151
actual_type: Type,

mypy/binder.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Frame:
3232
"""
3333

3434
def __init__(self) -> None:
35-
self.types = {} # type: Dict[Key, Type]
35+
self.types: Dict[Key, Type] = {}
3636
self.unreachable = False
3737

3838
# Should be set only if we're entering a frame where it's not
@@ -69,7 +69,7 @@ class A:
6969
"""
7070
# Stored assignments for situations with tuple/list lvalue and rvalue of union type.
7171
# This maps an expression to a list of bound types for every item in the union type.
72-
type_assignments = None # type: Optional[Assigns]
72+
type_assignments: Optional[Assigns] = None
7373

7474
def __init__(self) -> None:
7575
# The stack of frames currently used. These map
@@ -85,21 +85,21 @@ def __init__(self) -> None:
8585
# the end of the frame or by a loop control construct
8686
# or raised exception. The last element of self.frames
8787
# has no corresponding element in this list.
88-
self.options_on_return = [] # type: List[List[Frame]]
88+
self.options_on_return: List[List[Frame]] = []
8989

9090
# Maps literal_hash(expr) to get_declaration(expr)
9191
# for every expr stored in the binder
92-
self.declarations = {} # type: Dict[Key, Optional[Type]]
92+
self.declarations: Dict[Key, Optional[Type]] = {}
9393
# Set of other keys to invalidate if a key is changed, e.g. x -> {x.a, x[0]}
9494
# Whenever a new key (e.g. x.a.b) is added, we update this
95-
self.dependencies = {} # type: Dict[Key, Set[Key]]
95+
self.dependencies: Dict[Key, Set[Key]] = {}
9696

9797
# Whether the last pop changed the newly top frame on exit
9898
self.last_pop_changed = False
9999

100-
self.try_frames = set() # type: Set[int]
101-
self.break_frames = [] # type: List[int]
102-
self.continue_frames = [] # type: List[int]
100+
self.try_frames: Set[int] = set()
101+
self.break_frames: List[int] = []
102+
self.continue_frames: List[int] = []
103103

104104
def _add_dependencies(self, key: Key, value: Optional[Key] = None) -> None:
105105
if value is None:

0 commit comments

Comments
 (0)
0