diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index 4ece9ac4c94b..2c0bf9656d06 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -3320,8 +3320,6 @@ def fast_container_type( vt = join.join_type_list(values) if not isinstance(vt, Instance): return None - # TODO: update tests instead? - vt.erased = True return self.chk.named_generic_type(container_fullname, [vt]) def check_lst_expr(self, items: List[Expression], fullname: str, @@ -3448,9 +3446,6 @@ def fast_dict_type(self, e: DictExpr) -> Optional[Type]: return None if stargs and (stargs[0] != kt or stargs[1] != vt): return None - # TODO: update tests instead? - kt.erased = True - vt.erased = True return self.chk.named_generic_type('builtins.dict', [kt, vt]) def visit_dict_expr(self, e: DictExpr) -> Type: diff --git a/mypy/checkmember.py b/mypy/checkmember.py index e7af3978867f..16bd0e074c3f 100644 --- a/mypy/checkmember.py +++ b/mypy/checkmember.py @@ -842,12 +842,7 @@ def analyze_enum_class_attribute_access(itype: Instance, return None enum_literal = LiteralType(name, fallback=itype) - # When we analyze enums, the corresponding Instance is always considered to be erased - # due to how the signature of Enum.__new__ is `(cls: Type[_T], value: object) -> _T` - # in typeshed. However, this is really more of an implementation detail of how Enums - # are typed, and we really don't want to treat every single Enum value as if it were - # from type variable substitution. So we reset the 'erased' field here. - return itype.copy_modified(erased=False, last_known_value=enum_literal) + return itype.copy_modified(last_known_value=enum_literal) def analyze_typeddict_access(name: str, typ: TypedDictType, diff --git a/mypy/expandtype.py b/mypy/expandtype.py index 7e1645b75645..36cc83f439dd 100644 --- a/mypy/expandtype.py +++ b/mypy/expandtype.py @@ -93,9 +93,7 @@ def visit_type_var(self, t: TypeVarType) -> Type: repl = get_proper_type(self.variables.get(t.id, t)) if isinstance(repl, Instance): inst = repl - # Return copy of instance with type erasure flag on. - return Instance(inst.type, inst.args, line=inst.line, - column=inst.column, erased=True) + return Instance(inst.type, inst.args, line=inst.line, column=inst.column) else: return repl @@ -103,9 +101,7 @@ def visit_param_spec(self, t: ParamSpecType) -> Type: repl = get_proper_type(self.variables.get(t.id, t)) if isinstance(repl, Instance): inst = repl - # Return copy of instance with type erasure flag on. - return Instance(inst.type, inst.args, line=inst.line, - column=inst.column, erased=True) + return Instance(inst.type, inst.args, line=inst.line, column=inst.column) elif isinstance(repl, ParamSpecType): return repl.with_flavor(t.flavor) else: diff --git a/mypy/types.py b/mypy/types.py index 9fc0c1831a01..465af1c50e33 100644 --- a/mypy/types.py +++ b/mypy/types.py @@ -1029,19 +1029,16 @@ def try_getting_instance_fallback(typ: ProperType) -> Optional[Instance]: """ - __slots__ = ('type', 'args', 'erased', 'invalid', 'type_ref', 'last_known_value') + __slots__ = ('type', 'args', 'invalid', 'type_ref', 'last_known_value') def __init__(self, typ: mypy.nodes.TypeInfo, args: Sequence[Type], - line: int = -1, column: int = -1, erased: bool = False, + line: int = -1, column: int = -1, *, last_known_value: Optional['LiteralType'] = None) -> None: super().__init__(line, column) self.type = typ self.args = tuple(args) self.type_ref: Optional[str] = None - # True if result of type variable substitution - self.erased = erased - # True if recovered after incorrect number of type arguments error self.invalid = False @@ -1137,15 +1134,14 @@ def deserialize(cls, data: Union[JsonDict, str]) -> 'Instance': def copy_modified(self, *, args: Bogus[List[Type]] = _dummy, - erased: Bogus[bool] = _dummy, last_known_value: Bogus[Optional['LiteralType']] = _dummy) -> 'Instance': return Instance( self.type, args if args is not _dummy else self.args, self.line, self.column, - erased if erased is not _dummy else self.erased, - last_known_value if last_known_value is not _dummy else self.last_known_value, + last_known_value=last_known_value if last_known_value is not _dummy + else self.last_known_value, ) def has_readable_member(self, name: str) -> bool: