Skip to content
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

Fix __post_init_post_parse__ is incorrectly passed keyword arguments when no __post_init__ is defined #4361

Merged
merged 1 commit into from Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/4361-hramezani.md
@@ -0,0 +1 @@
Fix `__post_init_post_parse__` is incorrectly passed keyword arguments when no `__post_init__` is defined
3 changes: 1 addition & 2 deletions pydantic/dataclasses.py
Expand Up @@ -310,8 +310,7 @@ def new_init(self: 'Dataclass', *args: Any, **kwargs: Any) -> None:
# set arg value by default
initvars_and_values[f.name] = args[i]
except IndexError:
initvars_and_values[f.name] = f.default
initvars_and_values.update(kwargs)
initvars_and_values[f.name] = kwargs.get(f.name, f.default)

self.__post_init_post_parse__(**initvars_and_values)

Expand Down
11 changes: 11 additions & 0 deletions tests/test_dataclasses.py
Expand Up @@ -600,6 +600,17 @@ def __post_init_post_parse__(self, base_path):
assert PathDataPostInitPostParse('world', base_path='/hello').path == Path('/hello/world')


def test_post_init_post_parse_without_initvars():
@pydantic.dataclasses.dataclass
class Foo:
a: int

def __post_init_post_parse__(self):
...

Foo(a=1)


def test_classvar():
@pydantic.dataclasses.dataclass
class TestClassVar:
Expand Down