Skip to content

Commit

Permalink
Fix __post_init_post_parse__ is incorrectly passed keyword arguments …
Browse files Browse the repository at this point in the history
…when no __post_init__ is defined (#4361)
  • Loading branch information
hramezani committed Aug 11, 2022
1 parent 6650edf commit 149c05b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
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

0 comments on commit 149c05b

Please sign in to comment.