-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Fix some daemon crashes involving classes becoming generic #8157
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 2 commits
d84fc52
9f0d800
ab19890
6d369b5
272f53c
a39a249
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 |
---|---|---|
|
@@ -486,13 +486,15 @@ def visit_type_var(self, t: TypeVarType) -> ProperType: | |
def visit_instance(self, t: Instance) -> ProperType: | ||
if isinstance(self.s, Instance): | ||
si = self.s | ||
if t.type == si.type: | ||
if t.type == si.type and len(t.args) == len(si.args): | ||
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. Btw why do we need the 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, no, we definitely do not. The |
||
if is_subtype(t, self.s) or is_subtype(self.s 8000 , t): | ||
# Combine type arguments. We could have used join below | ||
# equivalently. | ||
args = [] # type: List[Type] | ||
for i in range(len(t.args)): | ||
args.append(self.meet(t.args[i], si.args[i])) | ||
# N.B: We use zip instead of indexing because the lengths might have | ||
# mismatches during daemon reprocessing. | ||
for ta, sia in zip(t.args, si.args): | ||
args.append(self.meet(ta, sia)) | ||
return Instance(t.type, args) | ||
else: | ||
if state.strict_optional: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9288,3 +9288,32 @@ class B: | |
self.x = 0 | ||
[out] | ||
== | ||
|
||
[case testGenericChange] | ||
import a | ||
[file a.py] | ||
import b | ||
def f() -> b.C: pass | ||
[file b.py] | ||
import a | ||
class C: pass | ||
[file b.py.2] | ||
from typing import TypeVar, Generic, Type, List | ||
import a | ||
|
||
T = TypeVar('T') | ||
class C(Generic[T]): pass | ||
|
||
reveal_type(a.f) | ||
c: C[int] | ||
l = a.f() if True else c | ||
d = a.f() | ||
d = c | ||
c = d | ||
|
||
x: List[C] = [a.f(), a.f()] | ||
|
||
[out] | ||
== | ||
b.py:7: note: Revealed type is 'def () -> b.C[Any]' | ||
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. What about a similar test case where a class goes from generic to non-generic? |
||
[builtins fixtures/list.pyi] |
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.
It's kind of unfortunate that we have to do this. Another option might be to make
args
a property and have it adjust the number of args dynamically if theTypeInfo
has changed. This could have performance impliciations, however.