Skip to content
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
Merge remote-tracking branch 'upstream/master' into generic-typeddict
  • Loading branch information
ilevkivskyi committed Aug 15, 2022
commit 8834fc260c61905a86f274e2fc0462346edd8905
3 changes: 3 additions & 0 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3768,6 +3768,9 @@ def visit_type_application(self, tapp: TypeApplication) -> Type:
if isinstance(item, Instance):
tp = type_object_type(item.type, self.named_type)
return self.apply_type_arguments_to_callable(tp, item.args, tapp)
elif isinstance(item, TupleType) and item.partial_fallback.type.is_named_tuple:
tp = type_object_type(item.partial_fallback.type, self.named_type)
return self.apply_type_arguments_to_callable(tp, item.partial_fallback.args, tapp)
elif isinstance(item, TypedDictType):
return self.typeddict_callable_from_context(item)
else:
Expand Down
13 changes: 10 additions & 3 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1424,8 +1424,13 @@ def setup_alias_type_vars(self, defn: ClassDef) -> None:
assert defn.info.special_alias is not None
defn.info.special_alias.alias_tvars = list(defn.info.type_vars)
>
assert isinstance(target, ProperType) and isinstance(target, TypedDictType)
target.fallback.args = tuple(defn.type_vars)
assert isinstance(target, ProperType)
if isinstance(target, TypedDictType):
target.fallback.args = tuple(defn.type_vars)
elif isinstance(target, TupleType):
target.partial_fallback.args = tuple(defn.type_vars)
else:
assert False, f"Unexpected special alias type: {type(target)}"

def is_core_builtin_class(self, defn: ClassDef) -> bool:
return self.cur_mod_id == "builtins" and defn.name in CORE_BUILTIN_CLASSES
Expand Down Expand Up @@ -1730,7 +1735,9 @@ def get_and_bind_all_tvars(self, type_exprs: List[Expression]) -> List[TypeVarLi
tvar_defs.append(tvar_def)
return tvar_defs

def prepare_class_def(self, defn: ClassDef, info: Optional[TypeInfo] = None) -> None:
def prepare_class_def(
self, defn: ClassDef, info: Optional[TypeInfo] = None, custom_names: bool = False
) -> None:
"""Prepare for the analysis of a class definition.

Create an empty TypeInfo and store it in a symbol table, or if the 'info'
Expand Down
23 changes: 23 additions & 0 deletions test-data/unit/check-incremental.test
Original file line number Diff line number Diff line change
Expand Up @@ -5911,6 +5911,29 @@ tmp/c.py:4: note: Revealed type is "TypedDict('a.N', {'r': Union[TypedDict('b.M'
tmp/c.py:5: error: Incompatible types in assignment (expression has type "Optional[N]", variable has type "int")
tmp/c.py:7: note: Revealed type is "TypedDict('a.N', {'r': Union[TypedDict('b.M', {'r': Union[..., None], 'x': builtins.int}), None], 'x': builtins.int})"

[case testGenericNamedTupleSerialization]
import b
[file a.py]
from typing import NamedTuple, Generic, TypeVar

T = TypeVar("T")
class NT(NamedTuple, Generic[T]):
key: int
value: T

[file b.py]
from a import NT
nt = NT(key=0, value="yes")
s: str = nt.value
[file b.py.2]
from a import NT
nt = NT(key=0, value=42)
s: str = nt.value
[builtins fixtures/tuple.pyi]
[out]
[out2]
tmp/b.py:3: error: Incompatible types in assignment (expression has type "int", variable has type "str")

[case testGenericTypedDictSerialization]
import b
[file a.py]
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.