-
Notifications
You must be signed in to change notification settings - Fork 287
Conformance suite: Minor tweaks to several assertions for better compatibility with ty #2178
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
base: main
Are you sure you want to change the base?
Changes from all commits
11875d9
652dde5
7b6a5d2
88bf117
9955ae1
d59f132
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 |
|---|---|---|
| @@ -1,26 +1,31 @@ | ||
| conformance_automated = "Pass" | ||
| conformance_automated = "Fail" | ||
| conformant = "Partial" | ||
| errors_diff = """ | ||
| Lines 15, 16: Expected error (tag 'fun1') | ||
| Lines 19, 20: Expected error (tag 'fun2') | ||
| Lines 49, 50: Expected error (tag 'method-str') | ||
| Lines 53, 54: Expected error (tag 'method-bytes') | ||
| """ | ||
| output = """ | ||
| generics_scoping.py:29: error: Argument 1 to "meth_2" of "MyClass" has incompatible type "str"; expected "int" [arg-type] | ||
| generics_scoping.py:50: error: Type variable "generics_scoping.S" is unbound [misc] | ||
| generics_scoping.py:50: note: (Hint: Use "Generic[S]" or "Protocol[S]" base class to bind "S" inside a class) | ||
| generics_scoping.py:50: note: (Hint: Use "S" in function signature to bind "S" inside a function) | ||
| generics_scoping.py:54: error: Type variable "generics_scoping.S" is unbound [misc] | ||
| generics_scoping.py:54: note: (Hint: Use "Generic[S]" or "Protocol[S]" base class to bind "S" inside a class) | ||
| generics_scoping.py:54: note: (Hint: Use "S" in function signature to bind "S" inside a function) | ||
| generics_scoping.py:65: error: Free type variable expected in Generic[...] [misc] | ||
| generics_scoping.py:75: error: Type variable "T" is bound by an outer class [misc] | ||
| generics_scoping.py:78: error: Type variable "T" is bound by an outer class [misc] | ||
| generics_scoping.py:80: error: Type variable "T" is bound by an outer class [misc] | ||
| generics_scoping.py:87: error: Can't use bound type variable "T" to define generic alias [misc] | ||
| generics_scoping.py:94: error: Type variable "generics_scoping.T" is unbound [misc] | ||
| generics_scoping.py:94: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class) | ||
| generics_scoping.py:94: note: (Hint: Use "T" in function signature to bind "T" inside a function) | ||
| generics_scoping.py:95: error: Type variable "generics_scoping.T" is unbound [misc] | ||
| generics_scoping.py:95: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class) | ||
| generics_scoping.py:95: note: (Hint: Use "T" in function signature to bind "T" inside a function) | ||
| generics_scoping.py:96: error: Type variable "generics_scoping.T" is unbound [misc] | ||
| generics_scoping.py:96: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class) | ||
| generics_scoping.py:96: note: (Hint: Use "T" in function signature to bind "T" inside a function) | ||
| generics_scoping.py:34: error: Argument 1 to "meth_2" of "MyClass" has incompatible type "str"; expected "int" [arg-type] | ||
| generics_scoping.py:61: error: Type variable "generics_scoping.S" is unbound [misc] | ||
| generics_scoping.py:61: note: (Hint: Use "Generic[S]" or "Protocol[S]" base class to bind "S" inside a class) | ||
| generics_scoping.py:61: note: (Hint: Use "S" in function signature to bind "S" inside a function) | ||
| generics_scoping.py:65: error: Type variable "generics_scoping.S" is unbound [misc] | ||
| generics_scoping.py:65: note: (Hint: Use "Generic[S]" or "Protocol[S]" base class to bind "S" inside a class) | ||
| generics_scoping.py:65: note: (Hint: Use "S" in function signature to bind "S" inside a function) | ||
| generics_scoping.py:76: error: Free type variable expected in Generic[...] [misc] | ||
| generics_scoping.py:86: error: Type variable "T" is bound by an outer class [misc] | ||
| generics_scoping.py:89: error: Type variable "T" is bound by an outer class [misc] | ||
| generics_scoping.py:91: error: Type variable "T" is bound by an outer class [misc] | ||
| generics_scoping.py:98: error: Can't use bound type variable "T" to define generic alias [misc] | ||
| generics_scoping.py:105: error: Type variable "generics_scoping.T" is unbound [misc] | ||
| generics_scoping.py:105: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class) | ||
| generics_scoping.py:105: note: (Hint: Use "T" in function signature to bind "T" inside a function) | ||
| generics_scoping.py:106: error: Type variable "generics_scoping.T" is unbound [misc] | ||
| generics_scoping.py:106: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class) | ||
| generics_scoping.py:106: note: (Hint: Use "T" in function signature to bind "T" inside a function) | ||
| generics_scoping.py:107: error: Type variable "generics_scoping.T" is unbound [misc] | ||
| generics_scoping.py:107: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class) | ||
| generics_scoping.py:107: note: (Hint: Use "T" in function signature to bind "T" inside a function) | ||
| """ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,23 +102,24 @@ def method3[T](self, x: T): # E | |
| T = int(0) | ||
|
|
||
|
|
||
| class Outer2[T]: | ||
|
Member
Author
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. the assertions in this test ran into issues because ty inferred ty also rejected the |
||
| T = int(1) | ||
|
|
||
| assert_type(T, int) | ||
| def f(a: int, b: str, c: complex): | ||
| class Outer2[T]: | ||
| T = a | ||
|
|
||
| class Inner1: | ||
| T = str("") | ||
| assert_type(T, int) | ||
|
|
||
| assert_type(T, str) | ||
| class Inner1: | ||
| T = b | ||
|
|
||
| def inner_method(self): | ||
| assert_type(T, TypeVar) | ||
| assert_type(T, str) | ||
|
|
||
| def outer_method(self): | ||
| T = 3j | ||
| def inner_method(self): | ||
| assert_type(T, TypeVar) | ||
|
|
||
| assert_type(T, complex) | ||
| def outer_method(self): | ||
| T = c | ||
|
|
||
| def inner_func(): | ||
| assert_type(T, complex) | ||
|
|
||
| def inner_func(): | ||
| assert_type(T, complex) | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
ty infers a "function-literal" type for
generator30, not aCallabletype. A function-literal type is more precise than aCallabletype: it retains, for example, the information thatgenerator30is an instance oftypes.FunctionType, which is not true for all arbitraryCallabletypes.I don't believe the spec states anywhere that type checkers must infer a
Callabletype for function objects (only that functions must be considered to inhabitCallabletypes), so I think this change is appropriate.I tried doing just
assert_type(generator30(), AsyncIterator[int]), but then zuban (reasonably) complained that the result ofgenerator30()was never awaited, which wasn't relevant to what the test was trying to assert.