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 c24a1e3 commit 52fd9a7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
11 changes: 6 additions & 5 deletions runtype/dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,15 +371,16 @@ def __post_init__(self):
# __init__ may have been generated by the dataclass function
if hasattr(c, "__init__"):
# We will add it to the dispatch
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__)
c.__init__ = init_dispatcher(_fix_qualname(c.__init__, cls))
else:
c.__init__ = init_f
return c

def _fix_qualname(f, cls):
if IS_BELOW_PY_310:
# XXX Hack for old Python versions, to fix __qualname__
f.__qualname__ = f"{cls.__qualname__}.{f.__name__}"
return f

def _dataclass_getstate(self):
return [getattr(self, f.name) for f in dataclasses.fields(self)]
Expand Down
7 changes: 1 addition & 6 deletions runtype/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,7 @@ def __call__(self, func=None, *, priority=None):
"Must either provide a function to decorate, or set a priority"
)

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:
fname = func.__qualname__
fname = func.__qualname__

try:
tree = self.fname_to_tree[fname]
Expand Down
2 changes: 1 addition & 1 deletion runtype/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import contextvars
from contextlib import contextmanager

IS_BELOW_PY_310 = sys.version_info < (3, 10)
IS_BELOW_PY_310 = True #sys.version_info < (3, 10)

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

0 comments on commit 52fd9a7

Please sign in to comment.