Skip to content

Commit

Permalink
Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Jan 26, 2024
1 parent 645f7f8 commit 7daacab
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
11 changes: 11 additions & 0 deletions docs/concepts/config.md
Expand Up @@ -98,6 +98,17 @@ class User:

Alternatively, the [`with_config`][pydantic.config.with_config] decorator can be used to comply with type checkers.

```py
from typing_extensions import TypedDict

from pydantic import ConfigDict, with_config


@with_config(ConfigDict(str_to_lower=True))
class Model(TypedDict):
x: str
```

## Change behaviour globally

If you wish to change the behaviour of Pydantic globally, you can create your own custom `BaseModel`
Expand Down
4 changes: 3 additions & 1 deletion pydantic/config.py
Expand Up @@ -913,7 +913,9 @@ class Model(BaseModel):


def with_config(config: ConfigDict) -> Callable[[_TypeT], _TypeT]:
"""A convenience decorator to set a [Pydantic configuration](config.md) on a `TypedDict` or a `dataclass` from the standard library.
"""Usage docs: https://docs.pydantic.dev/2.6/concepts/config/#configuration-with-dataclass-from-the-standard-library-or-typeddict
A convenience decorator to set a [Pydantic configuration](config.md) on a `TypedDict` or a `dataclass` from the standard library.
Although the configuration can be set using the `__pydantic_config__` attribute, it does not play well with type checkers,
especially with `TypedDict`.
Expand Down
@@ -0,0 +1,11 @@
from typing import TypedDict

from pydantic import ConfigDict, with_config


@with_config(ConfigDict(str_to_lower=True))
class Model(TypedDict):
a: str


model = Model(a='ABC')

0 comments on commit 7daacab

Please sign in to comment.