Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Make__signature__ lazy for dataclasses, too#10832

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
sydney-runkle merged 1 commit intomainfromlazy-sig-dcs
Nov 13, 2024
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletionspydantic/_internal/_dataclasses.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,6 +27,7 @@
from ._namespace_utils import NsResolver
from ._schema_generation_shared import CallbackGetCoreSchemaHandler
from ._signature import generate_pydantic_signature
from ._utils import LazyClassAttribute

if typing.TYPE_CHECKING:
from _typeshed import DataclassInstance as StandardDataclass
Expand DownExpand Up@@ -142,16 +143,21 @@ def __init__(__dataclass_self__: PydanticDataclass, *args: Any, **kwargs: Any) -
typevars_map=typevars_map,
)

# This needs to be called before we change the __init__
sig = generate_pydantic_signature(
init=original_init,
fields=cls.__pydantic_fields__, # type: ignore
populate_by_name=config_wrapper.populate_by_name,
extra=config_wrapper.extra,
is_dataclass=True,
# set __signature__ attr only for model class, but not for its instances
# (because instances can define `__call__`, and `inspect.signature` shouldn't
# use the `__signature__` attribute and instead generate from `__call__`).
cls.__signature__ = LazyClassAttribute(
'__signature__',
partial(
generate_pydantic_signature,
# It's' important that we reference the original_init here
init=original_init,
fields=cls.__pydantic_fields__, # type: ignore
populate_by_name=config_wrapper.populate_by_name,
extra=config_wrapper.extra,
is_dataclass=True,
),
)

cls.__signature__ = sig # type: ignore
get_core_schema = getattr(cls, '__get_pydantic_core_schema__', None)
try:
if get_core_schema:
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp