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

This commit is contained in:
Hasan Ramezani
2022-08-11 12:40:50 +02:00
committed by GitHub
parent 6650edfe8f
commit 149c05bc2e
3 changed files with 13 additions and 2 deletions
+1
View File
@@ -0,0 +1 @@
Fix `__post_init_post_parse__` is incorrectly passed keyword arguments when no `__post_init__` is defined
+1 -2
View File
@@ -310,8 +310,7 @@ def _add_pydantic_validation_attributes( # noqa: C901 (ignore complexity)
# 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)
+11
View File
@@ -600,6 +600,17 @@ def test_initvars_post_init_post_parse():
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: