Skip to content

Commit

Permalink
Crude workaround for AttributeError, no attribute "__create_fn__" (#72)
Browse files Browse the repository at this point in the history
Observed in python 3.8, constructor for dataclasses had different function signature
  • Loading branch information
ltan10 committed Feb 26, 2025
1 parent 8adaff5 commit 2a0a5de
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/lazydocs/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import re
import subprocess
import types
from dataclasses import dataclass
from dataclasses import dataclass, is_dataclass
from pydoc import locate
from typing import Any, Callable, Dict, List, Optional
from urllib.parse import quote
Expand Down Expand Up @@ -297,12 +297,19 @@ def _get_class_that_defined_method(meth: Any) -> Any:
mod = inspect.getmodule(meth)
if mod is None:
return None
cls = getattr(
inspect.getmodule(meth),
meth.__qualname__.split(".<locals>", 1)[0].rsplit(".", 1)[0],
)
if isinstance(cls, type):
return cls
try:
cls = getattr(
inspect.getmodule(meth),
meth.__qualname__.split(".<locals>", 1)[0].rsplit(".", 1)[0],
)
except AttributeError:
# workaround for AttributeError("module '<module name>' has no attribute '__create_fn__'")
for obj in meth.__globals__.values():
if is_dataclass(obj):
return obj
else:
if isinstance(cls, type):
return cls
return getattr(meth, "__objclass__", None) # handle special descriptor objects


Expand Down

0 comments on commit 2a0a5de

Please sign in to comment.