Skip to content

Commit

Permalink
Fix inherited typeddict attributes / config (#6981)
Browse files Browse the repository at this point in the history
  • Loading branch information
adriangb committed Aug 1, 2023
1 parent e86b529 commit bd725c7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pydantic/_internal/_generate_schema.py
Expand Up @@ -1046,7 +1046,12 @@ def _typed_dict_schema(self, typed_dict_cls: Any, origin: Any) -> core_schema.Co
code='typed-dict-version',
)

config = getattr(typed_dict_cls, '__pydantic_config__', None)
config: ConfigDict | None = None
for base in (typed_dict_cls, *typed_dict_cls.__orig_bases__):
config = getattr(base, '__pydantic_config__', None)
if config is not None:
break

with self._config_wrapper_stack.push(config):
core_config = self._config_wrapper.core_config(typed_dict_cls)

Expand Down
12 changes: 12 additions & 0 deletions tests/test_types_typeddict.py
Expand Up @@ -866,6 +866,18 @@ class Model(TypedDict):
assert ta.validate_python({'x': 'ABC'}) == {'x': 'abc'}


def test_model_config_inherited() -> None:
class Base(TypedDict):
__pydantic_config__ = ConfigDict(str_to_lower=True) # type: ignore

class Model(Base):
x: str

ta = TypeAdapter(Model)

assert ta.validate_python({'x': 'ABC'}) == {'x': 'abc'}


def test_schema_generator() -> None:
class LaxStrGenerator(GenerateSchema):
def str_schema(self) -> CoreSchema:
Expand Down

0 comments on commit bd725c7

Please sign in to comment.