8000 Use variable annotations by hauntsaninja · Pull Request #10723 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Use variable annotations #10723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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