Skip to content

Commit

Permalink
Clean up last traces of 'final_value' field (#6791)
Browse files Browse the repository at this point in the history
This pull request is a follow-up to #6763:
it renames some parameter names and variables that got missed up above.

One interesting side-note: it seems like 'Var' notes also contain a
`final_value` field that does almost the same thing as this
`last_known_value` field, but is ultimately unrelated: it was introduced
back in #5522. I decided to leave
this field alone.

(I discovered this while updating mypyc and discovered (to my surprise)
that nothing broke.)
  • Loading branch information
Michael0x2a authored and ilevkivskyi committed May 8, 2019
1 parent 56afa92 commit 285b683
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
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

0 comments on commit 285b683

Please sign in to comment.