Repository navigation
[ty] Specialize bare generic class name with type[...] type context - #29248
Conversation
Typing conformance results regressed ❌The percentage of diagnostics emitted that were expected errors decreased from 98.24% to 98.24%. The percentage of expected errors that received a diagnostic decreased from 98.24% to 98.24%. The number of fully passing files held steady at 134/146. SummaryHow are test cases classified?Each test case represents one expected error annotation or a group of annotations sharing a tag. Counts are per test case, not per diagnostic — multiple diagnostics on the same line count as one. Required annotations (
Test file breakdown1 file altered
Optional Diagnostics Removed (1)1 diagnostic
|
|
|
||
| # OK, the default specialization of `P` is assignable to `type[P[Unknown]]` | ||
| expects_type_p(P) | ||
| def _(bare: type[P]): # error: [missing-type-argument] |
There was a problem hiding this comment.
These tests were restructured so that the bare class name is default specialized instead of being affected by type context, to preserve the original intent of the tests. There are no semantic changes in this file.
cc15d79 to
02f069b
Compare
Memory usage reportMemory usage unchanged ✅ |
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
unsound-assignment |
0 | 6 | 0 |
invalid-assignment |
0 | 4 | 0 |
| Total | 0 | 10 | 0 |
Large timing changes:
| Project | Old Time | New Time | Change |
|---|---|---|---|
pyppeteer |
0.07s | 0.18s | +161% |
schema_salad |
0.20s | 0.45s | +121% |
Raw diff:
beartype (https://github.com/beartype/beartype)
- beartype/_check/code/codescope.py:398:33 warning[unsound-assignment] Unsound assignment: `list[Unknown]` is not a subtype of `list[type]`
- beartype/_check/code/codescope.py:402:36 warning[unsound-assignment] Unsound assignment: `list[Unknown]` is not a subtype of `list[type]`
- beartype/_check/code/_pep/pep484/codepep484604union.py:458:48 warning[unsound-assignment] Unsound assignment: `list[Unknown]` is not a subtype of `list[HintSane]`
prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/input/run_input.py:482:49 warning[unsound-assignment] Unsound assignment: `type[AutomaticRunInput[Unknown]]` is not a subtype of `type[AutomaticRunInput[T@AutomaticRunInput]]`
- src/prefect/server/utilities/database.py:405:34 warning[unsound-assignment] Unsound assignment: `<class 'REAL'>` is not a subtype of `type[REAL[float]]`
psycopg (https://github.com/psycopg/psycopg)
- psycopg/psycopg/connection.py:78:9 error[invalid-assignment] Object of type `<class 'Cursor'>` is not assignable to attribute `cursor_factory` of type `type[Cursor[Row@Connection]]`
- psycopg/psycopg/connection.py:79:9 error[invalid-assignment] Object of type `<class 'ServerCursor'>` is not assignable to attribute `server_cursor_factory` of type `type[ServerCursor[Row@Connection]]`
- psycopg/psycopg/connection_async.py:82:9 error[invalid-assignment] Object of type `<class 'AsyncCursor'>` is not assignable to attribute `cursor_factory` of type `type[AsyncCursor[Row@AsyncConnection]]`
- psycopg/psycopg/connection_async.py:83:9 error[invalid-assignment] Object of type `<class 'AsyncServerCursor'>` is not assignable to attribute `server_cursor_factory` of type `type[AsyncServerCursor[Row@AsyncConnection]]`
sympy (https://github.com/sympy/sympy)
- sympy/polys/domains/algebraicfield.py:265:24 warning[unsound-assignment] Unsound assignment: `<class 'ANP'>` is not a subtype of `type[ANP[MPQ]]`|
Hmm.. it looks like the conformance suite expects the motivating assignment to be disallowed? Pyright seems to have also changed its behavior since astral-sh/ty#1624 was filed. |
02f069b to
a41d831
Compare
|
The conformance suite issue is resolved by python/typing#2366. Pyright's behavior change appears to have been motivated entirely by the conformance suite, not by a real-world behavior preference: microsoft/pyright#11596 |
|
We'll also need to land #29269 and rebase this on it before the conformance CI will clear up. |
a41d831 to
70281a9
Compare
|
I rebased the PR on main. The conformance tests still say that "Typing conformance results regressed", but the optional |
|
We need to fix the script so that we no longer get a big angry ❌ if an optional diagnostic is removed... |
A
type[...]annotation should inform the specialization of a bare generic class:Resolves astral-sh/ty#1624.