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
  • Loading branch information
hramezani committed Aug 9, 2022
1 parent 11d8589 commit 1d68eb6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pydantic/dataclasses.py
Expand Up @@ -310,8 +310,10 @@ 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)
if f.name in kwargs:
initvars_and_values[f.name] = kwargs[f.name]
else:
initvars_and_values[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 1d68eb6

Please sign in to comment.