-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1.1 backport] [dataclass_transform] detect transform spec changes in…
… 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]>
- Loading branch information
1 parent
c03e979
commit f2cac4a
Showing
3 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
[case updateDataclassTransformParameterViaDecorator] | ||
# flags: --python-version 3.11 | ||
from m import my_dataclass | ||
|
||
@my_dataclass | ||
class Foo: | ||
x: int | ||
|
||
foo = Foo(1) | ||
foo.x = 2 | ||
|
||
[file m.py] | ||
from typing import dataclass_transform | ||
|
||
@dataclass_transform(frozen_default=False) | ||
def my_dataclass(cls): return cls | ||
|
||
[file m.py.2] | ||
from typing import dataclass_transform | ||
|
||
@dataclass_transform(frozen_default=True) | ||
def my_dataclass(cls): return cls | ||
|
||
[typing fixtures/typing-full.pyi] | ||
[builtins fixtures/dataclasses.pyi] | ||
|
||
[out] | ||
== | ||
main:9: error: Property "x" defined in "Foo" is read-only | ||
|
||
[case updateDataclassTransformParameterViaParentClass] | ||
# flags: --python-version 3.11 | ||
from m import Dataclass | ||
|
||
class Foo(Dataclass): | ||
x: int | ||
|
||
foo = Foo(1) | ||
foo.x = 2 | ||
|
||
[file m.py] | ||
from typing import dataclass_transform | ||
|
||
@dataclass_transform(frozen_default=False) | ||
class Dataclass: ... | ||
|
||
[file m.py.2] | ||
from typing import dataclass_transform | ||
|
||
@dataclass_transform(frozen_default=True) | ||
class Dataclass: ... | ||
|
||
[typing fixtures/typing-full.pyi] | ||
[builtins fixtures/dataclasses.pyi] | ||
|
||
[out] | ||
== | ||
main:8: error: Property "x" defined in "Foo" is read-only | ||
|
||
[case updateBaseClassToUseDataclassTransform] | ||
# flags: --python-version 3.11 | ||
from m import A | ||
|
||
class B(A): | ||
y: int | ||
|
||
B(x=1, y=2) | ||
|
||
[file m.py] | ||
class Dataclass: ... | ||
|
||
class A(Dataclass): | ||
x: int | ||
|
||
[file m.py.2] | ||
from typing import dataclass_transform | ||
|
||
@dataclass_transform() | ||
class Dataclass: ... | ||
|
||
class A(Dataclass): | ||
x: int | ||
|
||
[typing fixtures/typing-full.pyi] | ||
[builtins fixtures/dataclasses.pyi] | ||
|
||
[out] | ||
main:7: error: Unexpected keyword argument "x" for "B" | ||
builtins.pyi:12: note: "B" defined here | ||
main:7: error: Unexpected keyword argument "y" for "B" | ||
builtins.pyi:12: note: "B" defined here | ||
== |