10000 Merge TypeVarDef and TypeVarType by hauntsaninja · Pull Request #9951 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Merge TypeVarDef and TypeVarType #9951

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 13 commits into from
Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
more tvdef -> tv
  • Loading branch information
hauntsaninja committed Aug 4, 2021
commit ca294b43701022eca7e76f8814771f6de89db16a
30 changes: 15 additions & 15 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3277,15 +3277,15 @@ def check_lst_expr(self, items: List[Expression], fullname: str,
# Used for list and set expressions, as well as for tuples
# containing star expressions that don't refer to a
# Tuple. (Note: "lst" stands for list-set-tuple. :-)
tvdef = TypeVarType('T', 'T', -1, [], self.object_type())
tv = TypeVarType('T', 'T', -1, [], self.object_type())
constructor = CallableType(
[tvdef],
[tv],
[nodes.ARG_STAR],
[None],
self.chk.named_generic_type(fullname, [tvdef]),
self.chk.named_generic_type(fullname, [tv]),
self.named_type('builtins.function'),
name=tag,
variables=[tvdef])
variables=[tv])
out = self.check_call(constructor,
[(i.expr if isinstance(i, StarExpr) else i)
for i in items],
Expand Down Expand Up @@ -3434,22 +3434,22 @@ def visit_dict_expr(self, e: DictExpr) -> Type:
tup.column = value.column
args.append(tup)
# Define type variables (used in constructors below).
ktdef = TypeVarType('KT', 'KT', -1, [], self.object_type())
vtdef = TypeVarType('VT', 'VT', -2, [], self.object_type())
kt = TypeVarType('KT', 'KT', -1, [], self.object_type())
vt = TypeVarType('VT', 'VT', -2, [], self.object_type())
rv = None
# Call dict(*args), unless it's empty and stargs is not.
if args or not stargs:
# The callable type represents a function like this:
#
# def <unnamed>(*v: Tuple[kt, vt]) -> Dict[kt, vt]: ...
constructor = CallableType(
[TupleType([ktdef, vtdef], self.named_type('builtins.tuple'))],
[TupleType([kt, vt], self.named_type('builtins.tuple'))],
[nodes.ARG_STAR],
[None],
self.chk.named_generic_type('builtins.dict', [ktdef, vtdef]),
self.chk.named_generic_type('builtins.dict', [kt, vt]),
self.named_type('builtins.function'),
name='<dict>',
variables=[ktdef, vtdef])
variables=[kt, vt])
rv = self.check_call(constructor, args, [nodes.ARG_POS] * len(args), e)[0]
else:
# dict(...) will be called below.
Expand All @@ -3460,13 +3460,13 @@ def visit_dict_expr(self, e: DictExpr) -> Type:
for arg in stargs:
if rv is None:
constructor = CallableType(
[self.chk.named_generic_type('typing.Mapping', [ktdef, vtdef])],
[self.chk.named_generic_type('typing.Mapping', [kt, vt])],
[nodes.ARG_POS],
[None],
self.chk.named_generic_type('builtins.dict', [ktdef, vtdef]),
self.chk.named_generic_type('builtins.dict', [kt, vt]),
self.named_type('builtins.function'),
name='<list>',
variables=[ktdef, vtdef])
variables=[kt, vt])
rv = self.check_call(constructor, [arg], [nodes.ARG_POS], arg)[0]
else:
self.check_method_call_by_name('update', rv, [arg], [nodes.ARG_POS], arg)
Expand Down Expand Up @@ -3756,16 +3756,16 @@ def check_generator_or_comprehension(self, gen: GeneratorExpr,

# Infer the type of the list comprehension by using a synthetic generic
# callable type.
tvdef = TypeVarType('T', 'T', -1, [], self.object_type())
tv_list: List[Type] = [tvdef]
tv = TypeVarType('T', 'T', -1, [], self.object_type())
tv_list: List[Type] = [tv]
constructor = CallableType(
tv_list,
[nodes.ARG_POS],
[None],
self.chk.named_generic_type(type_name, tv_list + additional_args),
self.chk.named_type('builtins.function'),
name=id_for_messages,
variables=[tvdef])
variables=[tv])
return self.check_call(constructor,
[gen.left_expr], [nodes.ARG_POS], gen)[0]

Expand Down
1 change: 1 addition & 0 deletions mypy/expandtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
TypeAliasType, ParamSpecType
)


def expand_type(typ: Type, env: Mapping[TypeVarId, Type]) -> Type:
"""Substitute any type variable references in a type given by a type
environment.
Expand Down
0