Skip to content

Commit b44d2bc

Browse files
authored
Refactoring: Remove the "erased" attribute of Instance (#12499)
It's not used for anything.
1 parent 544d21a commit b44d2bc

File tree

4 files changed

+7
-25
lines changed

4 files changed

+7
-25
lines changed

mypy/checkexpr.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3320,8 +3320,6 @@ def fast_container_type(
33203320
vt = join.join_type_list(values)
33213321
if not isinstance(vt, Instance):
33223322
return None
3323-
# TODO: update tests instead?
3324-
vt.erased = True
33253323
return self.chk.named_generic_type(container_fullname, [vt])
33263324

33273325
def check_lst_expr(self, items: List[Expression], fullname: str,
@@ -3448,9 +3446,6 @@ def fast_dict_type(self, e: DictExpr) -> Optional[Type]:
34483446
return None
34493447
if stargs and (stargs[0] != kt or stargs[1] != vt):
34503448
return None
3451-
# TODO: update tests instead?
3452-
kt.erased = True
3453-
vt.erased = True
34543449
return self.chk.named_generic_type('builtins.dict', [kt, vt])
34553450

34563451
def visit_dict_expr(self, e: DictExpr) -> Type:

mypy/checkmember.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -842,12 +842,7 @@ def analyze_enum_class_attribute_access(itype: Instance,
842842
return None
843843

844844
enum_literal = LiteralType(name, fallback=itype)
845-
# When we analyze enums, the corresponding Instance is always considered to be erased
846-
# due to how the signature of Enum.__new__ is `(cls: Type[_T], value: object) -> _T`
847-
# in typeshed. However, this is really more of an implementation detail of how Enums
848-
# are typed, and we really don't want to treat every single Enum value as if it were
849-
# from type variable substitution. So we reset the 'erased' field here.
850-
return itype.copy_modified(erased=False, last_known_value=enum_literal)
845+
return itype.copy_modified(last_known_value=enum_literal)
851846

852847

853848
def analyze_typeddict_access(name: str, typ: TypedDictType,

mypy/expandtype.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,15 @@ def visit_type_var(self, t: TypeVarType) -> Type:
9393
repl = get_proper_type(self.variables.get(t.id, t))
9494
if isinstance(repl, Instance):
9595
inst = repl
96-
# Return copy of instance with type erasure flag on.
97-
return Instance(inst.type, inst.args, line=inst.line,
98-
column=inst.column, erased=True)
96+
return Instance(inst.type, inst.args, line=inst.line, column=inst.column)
9997
else:
10098
return repl
10199

102100
def visit_param_spec(self, t: ParamSpecType) -> Type:
103101
repl = get_proper_type(self.variables.get(t.id, t))
104102
if isinstance(repl, Instance):
105103
inst = repl
106-
# Return copy of instance with type erasure flag on.
107-
return Instance(inst.type, inst.args, line=inst.line,
108-
column=inst.column, erased=True)
104+
return Instance(inst.type, inst.args, line=inst.line, column=inst.column)
109105
elif isinstance(repl, ParamSpecType):
110106
return repl.with_flavor(t.flavor)
111107
else:

mypy/types.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,19 +1029,16 @@ def try_getting_instance_fallback(typ: ProperType) -> Optional[Instance]:
10291029
10301030
"""
10311031

1032-
__slots__ = ('type', 'args', 'erased', 'invalid', 'type_ref', 'last_known_value')
1032+
__slots__ = ('type', 'args', 'invalid', 'type_ref', 'last_known_value')
10331033

10341034
def __init__(self, typ: mypy.nodes.TypeInfo, args: Sequence[Type],
1035-
line: int = -1, column: int = -1, erased: bool = False,
1035+
line: int = -1, column: int = -1, *,
10361036
last_known_value: Optional['LiteralType'] = None) -> None:
10371037
super().__init__(line, column)
10381038
self.type = typ
10391039
self.args = tuple(args)
10401040
self.type_ref: Optional[str] = None
10411041

1042-
# True if result of type variable substitution
1043-
self.erased = erased
1044-
10451042
# True if recovered after incorrect number of type arguments error
10461043
self.invalid = False
10471044

@@ -1137,15 +1134,14 @@ def deserialize(cls, data: Union[JsonDict, str]) -> 'Instance':
11371134

11381135
def copy_modified(self, *,
11391136
args: Bogus[List[Type]] = _dummy,
1140-
erased: Bogus[bool] = _dummy,
11411137
last_known_value: Bogus[Optional['LiteralType']] = _dummy) -> 'Instance':
11421138
return Instance(
11431139
self.type,
11441140
args if args is not _dummy else self.args,
11451141
self.line,
11461142
self.column,
1147-
erased if erased is not _dummy else self.erased,
1148-
last_known_value if last_known_value is not _dummy else self.last_known_value,
1143+
last_known_value=last_known_value if last_known_value is not _dummy
1144+
else self.last_known_value,
11491145
)
11501146

11511147
def has_readable_member(self, name: str) -> bool:

0 commit comments

Comments
 (0)