-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
[dataclass_transform] detect transform spec changes in incremental mode #14695
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
Merged
JukkaL
merged 6 commits into
python:master
from
wesleywright:dataclass-transform-daemon-tests
Feb 22, 2023
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2abeb6d
[dataclass_transform] detect parameter changes in incremental mode
wesleywright 78a7092
always use tuple for deserializing field_specifiers
wesleywright 432c0a4
use serialized form for snapshots
wesleywright 5cb117b
fix updateBaseClassToUseDataclassTransform test
wesleywright 33ac67f
remove dangling newline
wesleywright 9def364
Merge branch 'master' of https://github.com/python/mypy into dataclas…
wesleywright File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 | ||
== |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thedataclass_transform
decorator.