Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
erezsh committed Aug 23, 2024
1 parent 7ecb85c commit c24a1e3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions runtype/dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def dataclass_transform(*a, **kw):
from .common import CHECK_TYPES
from .validation import TypeMismatchError, ensure_isa as default_ensure_isa
from .pytypes import TypeCaster, SumType, NoneType, ATypeCaster, PythonType, type_caster
from .utils import IS_BELOW_PY_310

Required = object()
Skip = object()
Expand Down Expand Up @@ -370,8 +371,11 @@ def __post_init__(self):
# __init__ may have been generated by the dataclass function
if hasattr(c, "__init__"):
# We will add it to the dispatch
# c.__init__ = init_dispatcher(c.__init__)
c.__init__ = init_dispatcher(c.__init__.__get__(cls))
if IS_BELOW_PY_310:
# XXX Hack for old Python versions, to fix __qualname__
c.__init__ = init_dispatcher(c.__init__.__get__(cls))
else:
c.__init__ = init_dispatcher(c.__init__)
else:
c.__init__ = init_f
return c
Expand Down
5 changes: 3 additions & 2 deletions runtype/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from dataclasses import dataclass

from .utils import get_func_signatures
from .utils import get_func_signatures, IS_BELOW_PY_310
from .typesystem import TypeSystem


Expand Down Expand Up @@ -50,7 +50,8 @@ def __call__(self, func=None, *, priority=None):
"Must either provide a function to decorate, or set a priority"
)

if hasattr(func, '__self__'):
if IS_BELOW_PY_310 and hasattr(func, '__self__'):
# XXX hack for old Python versions
fname = func.__self__.__qualname__ + "." + func.__name__
func = func.__func__
else:
Expand Down
3 changes: 3 additions & 0 deletions runtype/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import sys
import inspect
import contextvars
from contextlib import contextmanager

IS_BELOW_PY_310 = sys.version_info < (3, 10)

def get_func_signatures(typesystem, f):
sig = inspect.signature(f)
typesigs = []
Expand Down

0 comments on commit c24a1e3

Please sign in to comment.