-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[dataclass_transform] detect transform spec changes in incremental mode #14695
[dataclass_transform] detect transform spec changes in incremental mode #14695
Conversation
mypy/server/astdiff.py
Outdated
@@ -280,6 +283,7 @@ def snapshot_definition(node: SymbolNode | None, common: SymbolSnapshot) -> Symb | |||
tuple(snapshot_type(tdef) for tdef in node.defn.type_vars), | |||
[snapshot_type(base) for base in node.bases], | |||
[snapshot_type(p) for p in node._promote], | |||
node.dataclass_transform_spec or find_dataclass_transform_spec(node), |
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.
this may be somewhat expensive; an alternative may be to attach the relevant spec to each class in the hierarchy during semantic analysis rather than only attaching the spec to the transformer class
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.
Class hierarchies are almost always quite shallow, so this shouldn't be expensive. Similar to above, the snapshots must support equality. Using the serialized form should do the trick.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
The main thing here that doesn't seem right is that snapshots should only contain objects that support value-based equality. You can also add some test cases to test-data/unit/diff.test
which tests the astdiff
module.
mypy/server/astdiff.py
Outdated
@@ -239,6 +241,7 @@ def snapshot_definition(node: SymbolNode | None, common: SymbolSnapshot) -> Symb | |||
node.is_static, | |||
signature, | |||
is_trivial_body, | |||
dataclass_transform_spec, |
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.
This doesn't support equality and can't be used in snapshots. You can probably use the serialized form instead.
mypy/server/astdiff.py
Outdated
@@ -280,6 +283,7 @@ def snapshot_definition(node: SymbolNode | None, common: SymbolSnapshot) -> Symb | |||
tuple(snapshot_type(tdef) for tdef in node.defn.type_vars), | |||
[snapshot_type(base) for base in node.bases], | |||
[snapshot_type(p) for p in node._promote], | |||
node.dataclass_transform_spec or find_dataclass_transform_spec(node), |
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.
Class hierarchies are almost always quite shallow, so this shouldn't be expensive. Similar to above, the snapshots must support equality. Using the serialized form should do the trick.
@dataclass_transform() | ||
class Dataclass: ... | ||
|
||
class A(Dataclass): |
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.
Here the change in MRO will trigger dependencies, so this doesn't perfectly test how applying dataclass transform behaves. You can work around this by having a Dataclass
base class in the original version, but omit the dataclass_transform
decorator.
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
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.
Thanks, looks good now!
… incremental mode (python#14695) Adds support for triggering rechecking of downstream classes when `@dataclass_transform` is added or removed from a function/class, as well as when parameters to `dataclass_transform` are updated. These changes aren't propagated normally since they don't change the type signature of the `dataclass_transform` decorator. Also adds new a new `find-grained-dataclass-transform.test` file to test the new logic. (cherry picked from commit 29bcc7f)
… incremental mode (#14695) (#14768) Adds support for triggering rechecking of downstream classes when `@dataclass_transform` is added or removed from a function/class, as well as when parameters to `dataclass_transform` are updated. These changes aren't propagated normally since they don't change the type signature of the `dataclass_transform` decorator. Also adds new a new `find-grained-dataclass-transform.test` file to test the new logic. (cherry picked from commit 29bcc7f) Co-authored-by: Wesley Collin Wright <[email protected]>
Adds support for triggering rechecking of downstream classes when
@dataclass_transform
is added or removed from a function/class, as well as when parameters todataclass_transform
are updated. These changes aren't propagated normally since they don't change the type signature of thedataclass_transform
decorator.Also adds new a new
find-grained-dataclass-transform.test
file to test the new logic.