-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Self Type #2193
Self Type #2193
Changes from 48 commits
04934c3
4eb5f75
181ff09
25e104a
5e72623
29d2e0f
4d5d479
ea6c485
00596a6
39615c2
f8875f9
9ae3bf9
b29bf87
f097967
747c5b2
9b68a2f
65d6428
6c161b9
1cae034
733edc1
91946e2
abcb094
9f831c4
aade1ed
a6a0a3b
8e81051
a9b0b68
ec0f33a
09cd7bc
8b242e2
a8be2a6
3055ab0
72af252
bb2ac78
5f26cac
1f44c73
fcbcf4b
860c96a
b078d61
fc29a3a
2299a00
137f452
4bcbf59
6155c7f
47e5e2f
00ae83d
30f847e
c152c20
4f2017e
fddbba0
3cf8ecf
707da4e
48e139d
25b84f8
8944ff1
9221001
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
Type, AnyType, CallableType, Overloaded, NoneTyp, Void, TypeVarDef, | ||
TupleType, Instance, TypeVarId, TypeVarType, ErasedType, UnionType, | ||
PartialType, DeletedType, UnboundType, UninhabitedType, TypeType, | ||
true_only, false_only, is_named_instance | ||
true_only, false_only, is_named_instance, function_type | ||
) | ||
from mypy.nodes import ( | ||
NameExpr, RefExpr, Var, FuncDef, OverloadedFuncDef, TypeInfo, CallExpr, | ||
|
@@ -18,7 +18,6 @@ | |
DictionaryComprehension, ComplexExpr, EllipsisExpr, StarExpr, | ||
TypeAliasExpr, BackquoteExpr, ARG_POS, ARG_NAMED, ARG_STAR2, MODULE_REF, | ||
) | ||
from mypy.nodes import function_type | ||
from mypy import nodes | ||
import mypy.checker | ||
from mypy import types | ||
|
@@ -32,7 +31,7 @@ | |
from mypy import applytype | ||
from mypy import erasetype | ||
from mypy.checkmember import analyze_member_access, type_object_type | ||
from mypy.semanal import self_type | ||
from mypy.semanal import fill_typevars | ||
from mypy.constraints import get_actual_type | ||
from mypy.checkstrformat import StringFormatterChecker | ||
from mypy.expandtype import expand_type | ||
|
@@ -1609,10 +1608,17 @@ def analyze_super(self, e: SuperExpr, is_lvalue: bool) -> Type: | |
return AnyType() | ||
if not self.chk.in_checked_function(): | ||
return AnyType() | ||
return analyze_member_access(e.name, self_type(e.info), e, | ||
is_lvalue, True, False, | ||
self.named_type, self.not_ready_callback, | ||
self.msg, base, chk=self.chk) | ||
# fill_typevars(e.info) erases type variables | ||
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. This comment isn't right. 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. So I did get it wrong there. Yet if I pass I'm completely confused now :\ 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. Oh. wait. it's only confusing because we talk about different variables... sorry. I'll update. |
||
erased_self = fill_typevars(e.info) | ||
args = self.chk.function_stack[-1].arguments | ||
# An empty args with super() is an error, but we need something in declared_self | ||
declared_self = args[0].variable.type if args else erased_self | ||
return analyze_member_access(name=e.name, typ=erased_self, node=e, | ||
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. All the checker tests pass if I pass 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. I am not sure this will not break for generic classes. But perhaps we can wait and see. 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. Yeah, it could well break for generic classes, but as we don't have tests for them we don't know whether they work right now. Let's do that separately. Even for generic classes this is perhaps not the best approach. |
||
is_lvalue=False, is_super=True, is_operator=False, | ||
builtin_type=self.named_type, | ||
not_ready_callback=self.not_ready_callback, | ||
msg=self.msg, override_info=base, chk=self.chk, | ||
actual_self=declared_self) | ||
else: | ||
# Invalid super. This has been reported by the semantic analyzer. | ||
return AnyType() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comment about needing to the type variable check recursively for the argument types. For example,
Iteratble[T]
is not a valid argument type ifT
is covariant.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added, though I am not entirely sure I understood