Skip to content

Commit 2a0a5de

Browse files
committed
Crude workaround for AttributeError, no attribute "__create_fn__" (#72)
Observed in python 3.8, constructor for dataclasses had different function signature
1 parent 8adaff5 commit 2a0a5de

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/lazydocs/generation.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import re
1010
import subprocess
1111
import types
12-
from dataclasses import dataclass
12+
from dataclasses import dataclass, is_dataclass
1313
from pydoc import locate
1414
from typing import Any, Callable, Dict, List, Optional
1515
from urllib.parse import quote
@@ -297,12 +297,19 @@ def _get_class_that_defined_method(meth: Any) -> Any:
297297
mod = inspect.getmodule(meth)
298298
if mod is None:
299299
return None
300-
cls = getattr(
301-
inspect.getmodule(meth),
302-
meth.__qualname__.split(".<locals>", 1)[0].rsplit(".", 1)[0],
303-
)
304-
if isinstance(cls, type):
305-
return cls
300+
try:
301+
cls = getattr(
302+
inspect.getmodule(meth),
303+
meth.__qualname__.split(".<locals>", 1)[0].rsplit(".", 1)[0],
304+
)
305+
except AttributeError:
306+
# workaround for AttributeError("module '<module name>' has no attribute '__create_fn__'")
307+
for obj in meth.__globals__.values():
308+
if is_dataclass(obj):
309+
return obj
310+
else:
311+
if isinstance(cls, type):
312+
return cls
306313
return getattr(meth, "__objclass__", None) # handle special descriptor objects
307314

308315

0 commit comments

Comments
 (0)