Skip to content

Clean up last traces of 'final_value' field #6791

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
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/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1804,7 +1804,7 @@ def infer_literal_expr_type(self, value: LiteralValue, fallback_name: str) -> Ty
if self.is_literal_context():
return LiteralType(value=value, fallback=typ)
else:
return typ.copy_modified(final_value=LiteralType(
return typ.copy_modified(last_known_value=LiteralType(
value=value,
fallback=typ,
line=typ.line,
Expand Down
2 changes: 1 addition & 1 deletion mypy/erasetype.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,5 @@ class LastKnownValueEraser(TypeTranslator):

def visit_instance(self, t: Instance) -> Type:
if t.last_known_value:
return t.copy_modified(final_value=None)
return t.copy_modified(last_known_value=None)
return t
2 changes: 1 addition & 1 deletion mypy/newsemanal/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2223,7 +2223,7 @@ def analyze_simple_literal_type(self, rvalue: Expression, is_final: bool) -> Opt
assert value is not None
typ = self.named_type_or_none(type_name)
if typ and is_final:
return typ.copy_modified(final_value=LiteralType(
return typ.copy_modified(last_known_value=LiteralType(
value=value,
fallback=typ,
line=typ.line,
Expand Down
2 changes: 1 addition & 1 deletion mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1978,7 +1978,7 @@ def analyze_simple_literal_type(self, rvalue: Expression, is_final: bool) -> Opt
assert value is not None
typ = self.named_type_or_none(type_name)
if typ and is_final:
return typ.copy_modified(final_value=LiteralType(
return typ.copy_modified(last_known_value=LiteralType(
value=value,
fallback=typ,
line=typ.line,
Expand Down
10 changes: 5 additions & 5 deletions mypy/type_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,17 @@ def visit_deleted_type(self, t: DeletedType) -> Type:
return t

def visit_instance(self, t: Instance) -> Type:
final_value = None # type: Optional[LiteralType]
last_known_value = None # type: Optional[LiteralType]
if t.last_known_value is not None:
raw_final_value = t.last_known_value.accept(self)
assert isinstance(raw_final_value, LiteralType)
final_value = raw_final_value
raw_last_known_value = t.last_known_value.accept(self)
assert isinstance(raw_last_known_value, LiteralType)
last_known_value = raw_last_known_value
return Instance(
typ=t.type,
args=self.translate_types(t.args),
line=t.line,
column=t.column,
last_known_value=final_value,
last_known_value=last_known_value,
)

def visit_type_var(self, t: TypeVarType) -> Type:
Expand Down
4 changes: 2 additions & 2 deletions mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,14 +692,14 @@ def deserialize(cls, data: Union[JsonDict, str]) -> 'Instance':

def copy_modified(self, *,
args: Bogus[List[Type]] = _dummy,
final_value: Bogus[Optional['LiteralType']] = _dummy) -> 'Instance':
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,
self.erased,
final_value if final_value is not _dummy else self.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:
Expand Down