mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
Fix __post_init_post_parse__ is incorrectly passed keyword arguments when no __post_init__ is defined (#4361)
This commit is contained in:
@@ -0,0 +1 @@
|
||||
Fix `__post_init_post_parse__` is incorrectly passed keyword arguments when no `__post_init__` is defined
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user