Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds dataclass_transform to dataclass #4007

Merged
merged 3 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/4006-giuliano-oliveira.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for autocomplete in VS Code via `__dataclass_transform__` when using `pydantic.dataclasses.dataclass`
17 changes: 10 additions & 7 deletions pydantic/dataclasses.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import TYPE_CHECKING, Any, Callable, Dict, Optional, Type, TypeVar, Union, overload
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Dict, Optional, Type, TypeVar, Union, overload

from .class_validators import gather_all_validators
from .error_wrappers import ValidationError
from .errors import DataclassTypeError
from .fields import Field, FieldInfo, Required, Undefined
from .main import create_model, validate_model
from .main import __dataclass_transform__, create_model, validate_model
from .typing import resolve_annotations
from .utils import ClassAttribute

Expand All @@ -16,11 +16,11 @@
DataclassT = TypeVar('DataclassT', bound='Dataclass')

class Dataclass:
__pydantic_model__: Type[BaseModel]
__initialised__: bool
__post_init_original__: Optional[Callable[..., None]]
__processed__: Optional[ClassAttribute]
__has_field_info_default__: bool # whether or not a `pydantic.Field` is used as default value
__pydantic_model__: ClassVar[Type[BaseModel]]
__initialised__: ClassVar[bool]
__post_init_original__: ClassVar[Optional[Callable[..., None]]]
__processed__: ClassVar[Optional[ClassAttribute]]
__has_field_info_default__: ClassVar[bool] # whether or not a `pydantic.Field` is used as default value

def __init__(self, *args: Any, **kwargs: Any) -> None:
pass
Expand Down Expand Up @@ -206,6 +206,7 @@ def _process_class(
return cls


@__dataclass_transform__(kw_only_default=True, field_descriptors=(Field, FieldInfo))
@overload
def dataclass(
*,
Expand All @@ -220,6 +221,7 @@ def dataclass(
...


@__dataclass_transform__(kw_only_default=True, field_descriptors=(Field, FieldInfo))
@overload
def dataclass(
_cls: Type[Any],
Expand All @@ -235,6 +237,7 @@ def dataclass(
...


@__dataclass_transform__(kw_only_default=True, field_descriptors=(Field, FieldInfo))
def dataclass(
_cls: Optional[Type[Any]] = None,
*,
Expand Down