-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Fix crashes and fails in forward references #3952
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 1 commit
45e5931
cb4caa5
1cdc980
260ef02
a58a217
950a022
411b24d
b9b8528
48d6de4
ec45441
ac32ed4
3fb3019
f9b1320
cf014b8
665236b
9a318aa
757fbd9
4502ce2
3b39d40
c8b28fe
9f92b0f
9779103
b914bdb
3568fdb
54d9331
b9ddacc
5bfe9ca
a2912e9
10c65b8
21dfbfe
f2ddbcd
03597ee
649ef32
83f8907
13c7176
79b10d6
321a809
076c909
c1a63ec
97e6f47
8f52654
6edd078
514b8bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -434,6 +434,20 @@ def f() -> None: | |
A = NamedTuple('A', [('x', int)]) | ||
A # E: Name 'A' is not defined | ||
|
||
[case testNamedTupleForwardAsUpperBound] | ||
from typing import NamedTuple, TypeVar, Generic | ||
T = TypeVar('T', bound='M') | ||
class G(Generic[T]): | ||
x: T | ||
|
||
yb: G[int] | ||
yg: G[M] | ||
z: int = G[M]().x.x | ||
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. Using |
||
z = G[M]().x[0] | ||
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.
|
||
|
||
M = NamedTuple('M', [('x', int)]) | ||
[out] | ||
|
||
[case testNamedTupleWithImportCycle] | ||
import a | ||
[file a.py] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1565,3 +1565,28 @@ reveal_type(d['weight0']) # E: Revealed type is 'builtins.float*' | |
|
||
[builtins fixtures/floatdict.pyi] | ||
|
||
[case testForwardRefsInForStatement] | ||
from typing import List, NamedTuple | ||
lst: List[N] | ||
|
||
for i in lst: # type: N | ||
a: int = i.x | ||
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. Again, prefer |
||
b: str = i[0] | ||
|
||
N = NamedTuple('N', [('x', int)]) | ||
[builtins fixtures/list.pyi] | ||
[out] | ||
|
||
[case testForwardRefsInWithStatement] | ||
from typing import ContextManager | ||
from mypy_extensions import TypedDict | ||
cm: ContextManager[N] | ||
|
||
with cm as g: # type: N | ||
a: str = g['x'] | ||
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.
|
||
|
||
N = TypedDict('N', {'x': int}) | ||
[builtins fixtures/dict.pyi] | ||
[typing fixtures/typing-full.pyi] | ||
[out] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1326,6 +1326,22 @@ reveal_type(m['director']['name']) # E: Revealed type is 'builtins.str' | |
[builtins fixtures/dict.pyi] | ||
[out] | ||
|
||
[case testTypedDictForwardAsUpperBound] | ||
from typing import TypeVar, Generic | ||
from mypy_extensions import TypedDict | ||
T = TypeVar('T', bound='M') | ||
class G(Generic[T]): | ||
x: T | ||
|
||
yb: G[int] | ||
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. Similar to above, shouldn' 916A t this be rejected? 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 is rejected, here and above. I see the problem, it looks like you reviewed only a commit range, not all changes in PR. I will anyway go though all comments this evening. Thanks for review! |
||
yg: G[M] | ||
z: int = G().x['x'] | ||
|
||
class M(TypedDict): | ||
x: int | ||
[builtins fixtures/dict.pyi] | ||
[out] | ||
|
||
[case testTypedDictWithImportCycleForward] | ||
import a | ||
[file a.py] | ||
|
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.
Shouldn't this be rejected, since
int
is not compatible withM
?