[ty] Add support for types.new_class#23144
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 87.72%. The percentage of expected errors that received a diagnostic held steady at 82.85%. The number of fully passing files held steady at 74/132. |
4f5f14c to
876eead
Compare
|
d90ba3d to
171e68c
Compare
171e68c to
5ec4d35
Compare
|
I'll mark as draft pending #22792. |
5ec4d35 to
dce1aba
Compare
Memory usage reportMemory usage unchanged ✅ |
ac8a81b to
db7116d
Compare
fdac492 to
15d3318
Compare
|
Closing and reopening this to test the PR auto-assignment workflow. |
580f562 to
fe529c8
Compare
fe529c8 to
a3a688a
Compare
|
Sorry I haven't got to this yet, it is on the list... |
|
Don't worry, it's not urgent, I'm just trying to rebase all my stuff semi-regularly. |
|
This looks reasonable -- if it's rebased (again) I'll properly review it. |
a3a688a to
341afa8
Compare
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-await |
40 | 0 | 0 |
invalid-return-type |
1 | 1 | 0 |
unresolved-attribute |
0 | 2 | 0 |
invalid-base |
1 | 0 | 0 |
not-subscriptable |
0 | 0 | 1 |
unsupported-dynamic-base |
1 | 0 | 0 |
| Total | 43 | 3 | 1 |
Changes in flaky projects detected. Raw diff output excludes flaky projects; see the HTML report for details.
Raw diff:
attrs (https://github.com/python-attrs/attrs)
- src/attr/_cmp.py:98:9 error[unresolved-attribute] Object of type `type` has no attribute `_requirements`
+ tests/test_make.py:1512:43 error[invalid-base] Invalid base for class created via `types.new_class()`: Has type `<special-form 'typing.Generic[MyTypeVar]'>`
- tests/test_make.py:1514:61 error[not-subscriptable] Cannot subscript object of type `type` with no `__class_getitem__` method
+ tests/test_make.py:1514:61 error[not-subscriptable] Cannot subscript object of type `<class 'MyParent'>` with no `__getitem__` method
spack (https://github.com/spack/spack)
- lib/spack/spack/vendor/attr/_cmp.py:88:9 error[unresolved-attribute] Object of type `type` has no attribute `_requirements`
strawberry (https://github.com/strawberry-graphql/strawberry)
- strawberry/tools/create_type.py:71:12 error[invalid-return-type] Return type does not match returned value: expected `type`, found `<decorator produced by dataclass-like function>`
trio (https://github.com/python-trio/trio)
+ src/trio/_tests/test_exports.py:86:44 warning[unsupported-dynamic-base] Unsupported class base: Has type `type`
carljm
left a comment
There was a problem hiding this comment.
Looks good overall! I think the regression around SubclassOf types is the only blocking issue.
4925377 to
5568da1
Compare
| // deferred along with bases inference. | ||
| if let Some(explicit_bases) = &explicit_bases { | ||
| // Validate bases and collect disjoint bases for diagnostics. | ||
| let mut disjoint_bases = self.validate_dynamic_type_bases( |
There was a problem hiding this comment.
nit: there are still methods like this that are only used/shared by type-call and types-new-class, but still live in the main infer/builder.rs. Almost feels like we should have infer/builder/dynamic_class.rs and then infer/builder/dynamic_class/type_call.rs and infer/builder/dynamic_class/new_class.rs
5568da1 to
87799bd
Compare
## Summary Addresses: #23144 (comment).
Summary
Generally straightforward given that we support
type(...); however, I think the base class validation can be a bit looser, sincetypes.new_classdoes proper metaclass resolution.Closes astral-sh/ty#2399.