Skip to content

Commit

Permalink
Use variable annotations (#10723)
Browse files Browse the repository at this point in the history
* 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 <>
  • Loading branch information
hauntsaninja authored Jun 28, 2021
1 parent 9851cce commit f98f782
Show file tree
Hide file tree
Showing 153 changed files with 2,173 additions and 2,055 deletions.
2 changes: 1 addition & 1 deletion mypy/applytype.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def apply_generic_arguments(
types = get_proper_types(orig_types)

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

for tvar, type in zip(tvars, types):
assert not isinstance(type, PartialType), "Internal error: must never apply partial type"
Expand Down
8 changes: 4 additions & 4 deletions mypy/argmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def map_actuals_to_formals(actual_kinds: List[int],
argument type with the given index.
"""
nformals = len(formal_kinds)
formal_to_actual = [[] for i in range(nformals)] # type: List[List[int]]
ambiguous_actual_kwargs = [] # type: List[int]
formal_to_actual: List[List[int]] = [[] for i in range(nformals)]
ambiguous_actual_kwargs: List[int] = []
fi = 0
for ai, actual_kind in enumerate(actual_kinds):
if actual_kind == nodes.ARG_POS:
Expand Down Expand Up @@ -112,7 +112,7 @@ def map_formals_to_actuals(actual_kinds: List[int],
formal_names,
actual_arg_type)
# Now reverse the mapping.
actual_to_formal = [[] for _ in actual_kinds] # type: List[List[int]]
actual_to_formal: List[List[int]] = [[] for _ in actual_kinds]
for formal, actuals in enumerate(formal_to_actual):
for actual in actuals:
actual_to_formal[actual].append(formal)
Expand Down Expand Up @@ -145,7 +145,7 @@ def __init__(self) -> None:
# Next tuple *args index to use.
self.tuple_index = 0
# Keyword arguments in TypedDict **kwargs used.
self.kwargs_used = set() # type: Set[str]
self.kwargs_used: Set[str] = set()

def expand_actual_type(self,
actual_type: Type,
Expand Down
16 changes: 8 additions & 8 deletions mypy/binder.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Frame:
"""

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

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

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

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

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

self.try_frames = set() # type: Set[int]
self.break_frames = [] # type: List[int]
self.continue_frames = [] # type: List[int]
self.try_frames: Set[int] = set()
self.break_frames: List[int] = []
self.continue_frames: List[int] = []

def _add_dependencies(self, key: Key, value: Optional[Key] = None) -> None:
if value is None:
Expand Down
Loading

0 comments on commit f98f782

Please sign in to comment.