-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Add interactions between Literal and Final #6081
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
Changes from all commits
e5a7495
7335991
85fab7d
dd68816
55a38ce
118ff58
d37079c
5969196
da6807f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
|
||
from abc import abstractmethod | ||
from collections import OrderedDict | ||
from typing import Generic, TypeVar, cast, Any, List, Callable, Iterable | ||
from typing import Generic, TypeVar, cast, Any, List, Callable, Iterable, Optional | ||
from mypy_extensions import trait | ||
|
||
T = TypeVar('T') | ||
|
@@ -159,7 +159,18 @@ def visit_deleted_type(self, t: DeletedType) -> Type: | |
return t | ||
|
||
def visit_instance(self, t: Instance) -> Type: | ||
return Instance(t.type, self.translate_types(t.args), t.line, t.column) | ||
final_value = None # type: Optional[LiteralType] | ||
if t.final_value is not None: | ||
raw_final_value = t.final_value.accept(self) | ||
assert isinstance(raw_final_value, LiteralType) | ||
final_value = raw_final_value | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why can't you just write: final_value = t.final_value.accept(self)
assert isinstance(final_value, LiteralType) thus avoiding the extra variable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's because I can replace this entire if statement with a cast if you want, similar to what we're doing in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will my version work if you remove the type comment on (This is not important however.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alas, it doesn't: I get a 'Argument "final_value" to "Instance" has incompatible type "Optional[Type]"; expected "Optional[LiteralType]"` error a little later on when we use the variable. |
||
return Instance( | ||
typ=t.type, | ||
args=self.translate_types(t.args), | ||
line=t.line, | ||
column=t.column, | ||
final_value=final_value, | ||
) | ||
|
||
def visit_type_var(self, t: TypeVarType) -> Type: | ||
return t | ||
|
Uh oh!
There was an error while loading. Please reload this page.