[ty] Dataclass transform: neither frozen nor non-frozen#23366
Conversation
Typing conformance results improved 🎉The percentage of diagnostics emitted that were expected errors increased from 84.87% to 84.90%. The percentage of expected errors that received a diagnostic increased from 75.14% to 75.32%. Summary
True positives addedDetails
|
Memory usage reportMemory usage unchanged ✅ |
|
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
unsupported-operator |
87 | 0 | 0 |
invalid-await |
40 | 0 | 0 |
unresolved-attribute |
5 | 0 | 0 |
invalid-argument-type |
3 | 0 | 0 |
invalid-return-type |
1 | 0 | 0 |
| Total | 136 | 0 | 0 |
088b523 to
3207d6d
Compare
| from typing import dataclass_transform | ||
|
|
||
| @dataclass_transform() | ||
| @dataclass_transform(frozen_default=True) |
There was a problem hiding this comment.
Look, we found a mistake in our tests. This should be frozen so that TemperatureSensor below can be frozen. I checked and this is actually the case in home assistant. I just forgot to include it at the time.
3207d6d to
75536ce
Compare
75536ce to
964dadf
Compare
| && let (Some(base_params), Some(class_params)) = ( | ||
| base_class_literal.dataclass_params(self.db()), | ||
| class.dataclass_params(self.db()), | ||
| && let (Some(base_is_frozen), Some(class_is_frozen)) = ( |
There was a problem hiding this comment.
Out of curiosity, is it even possible for class.is_frozen_dataclass to be None here? I guess it could be if both the base class and the subclass specify metaclass=?
There was a problem hiding this comment.
Out of curiosity, is it even possible for class.is_frozen_dataclass to be None here?
Hmm.. probably not? Even if the class itself has a metaclass that is not a dataclass_transformer, we would still walk the MRO upward to find a base class with a dataclass_transform-decorated metaclass. In other words, if a base class is a dataclass_transformer for some reason, then all subclasses will also have dataclass parameters somehow, and therefore return Some(…)
* main: [ty] Take myself out of the reviewer pool for the next few days (#23618) [ty] Fix bug where ty would think that a `Callable` with a variadic positional parameter could be a subtype of a `Callable` with a positional-or-keyword parameter (#23610) [`ruff`] Add fix for `none-not-at-end-of-union` (`RUF036`) (#22829) Bump cargo dist to 0.31 (#23614) [`pyflakes`] Fix false positive for names shadowing re-exports (`F811`) (#23356) [`fastapi`] Handle callable class dependencies with `__call__` method (`FAST003`) (#23553) [ty] Recurse into tuples and nested tuples when applying special-cased validation of `isinstance()` and `issubclass()` (#23607) Update typing conformance suite commit (#23606) [ty] Detect invalid uses of `@final` on non-methods (#23604) [ty] Move the type hierarchy request handlers to individual modules [ty] Wire up the type hierarchy implementation with the LSP [ty] Add routine for mapping from system path to vendored path [ty] Implement internal routines for providing the LSP "type hierarchy" feature [ty] Add some helper methods on `ClassLiteral` [ty] Move some module name helper routines to methods on `ModuleName` [ty] Bump version of `lsp-types` [ty] Refactor to support building constraint sets differently (#23600) [ty] Dataclass transform: neither frozen nor non-frozen (#23366) [ty] Add snapshot tests for advanced `invalid-assignment` scenarios (#23581) [ty] disallow negative narrowing on SubclassOf types (#23598)
Summary
Implement the semantics described here in the typing spec:
Test Plan
New Markdown tests for all flavors of
dataclass_transformers.