Skip to content

Commit

Permalink
Merge pull request #12 from erezsh/pep681
Browse files Browse the repository at this point in the history
Added support for PEP 0681 - dataclass_transform
  • Loading branch information
erezsh authored Nov 26, 2022
2 parents 1fc4745 + 14197e9 commit 00c9f7a
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions runtype/dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import random
from copy import copy
import dataclasses
from typing import Union
from typing import Union, Any, Tuple, Callable, TypeVar
from abc import ABC, abstractmethod
import inspect

Expand Down Expand Up @@ -319,9 +319,22 @@ def _add_slots(cls, is_frozen):
return cls


# This is a super-ugly hack called PEP-0681. https://peps.python.org/pep-0681/
_T = TypeVar("_T")
def __dataclass_transform__(
*,
eq_default: bool = True,
order_default: bool = False,
kw_only_default: bool = False,
field_descriptors: Tuple[Union[type, Callable[..., Any]], ...] = (()),
) -> Callable[[_T], _T]:
return lambda a: a


@__dataclass_transform__(eq_default=True, order_default=True)
def dataclass(cls=None, *, check_types: Union[bool, str] = CHECK_TYPES,
config: Configuration = PythonConfiguration(),
init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=True, slots=False):
init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=True, slots=False) -> Any:
"""Runtype's dataclass is a drop-in replacement to Python's built-in dataclass, with added functionality.
**Differences from builtin dataclass:**
Expand Down

0 comments on commit 00c9f7a

Please sign in to comment.