[Enhancement] magic/dunder methods
Closed this issue · 6 comments
Ahrak commented
Currently magic/dunder methods are not handled by mkapi:
e.g.:
__add__
__mul__
__eq__
__repr__
__str__
__len__
- ...
Would be nice to have them in the API docs if they are documented.
daizutabi commented
I fixed the issue in released Version 0.7.5.
You can check an example output here
Ahrak commented
Thx for the quick "bugfix" but with it seems there is an problem with the __call__
method and inheritance:
quick example:
""" base module """
from __future__ import annotations
import abc
class Foo(abc.ABC):
def __init__(self):
"""Constructor"""
pass
@abc.abstractmethod
def blubb(self, x):
raise NotImplementedError
class Bar(abc.ABC):
_x: int = 0
def __init__(self):
#""" sdhsehes """
x = 0
def blubb(self, x):
""" blubb """
self._x = x
def __call__(self, x):
""" pls call me :-) """
return self.blubb(x)
trace:
Traceback (most recent call last):
File "./test-mkapi/.env/bin/mkdocs", line 8, in <module>
sys.exit(cli())
File "./test-mkapi/.env/lib/python3.7/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "./test-mkapi/.env/lib/python3.7/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "./test-mkapi/.env/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "./test-mkapi/.env/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "./test-mkapi/.env/lib/python3.7/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "./test-mkapi/.env/lib/python3.7/site-packages/mkdocs/__main__.py", line 152, in build_command
build.build(config.load_config(**kwargs), dirty=not clean)
File "./test-mkapi/.env/lib/python3.7/site-packages/mkdocs/commands/build.py", line 271, in build
_populate_page(file.page, config, files, dirty)
File "./test-mkapi/.env/lib/python3.7/site-packages/mkdocs/commands/build.py", line 167, in _populate_page
page.markdown = config['plugins'].run_event(
File "./test-mkapi/.env/lib/python3.7/site-packages/mkdocs/plugins.py", line 94, in run_event
result = method(item, **kwargs)
File "./test-mkapi/.env/lib/python3.7/site-packages/mkapi/plugins/mkdocs.py", line 85, in on_page_markdown
page = Page(markdown, abs_src_path, self.abs_api_paths)
File "<string>", line 6, in __init__
File "./test-mkapi/.env/lib/python3.7/site-packages/mkapi/core/page.py", line 36, in __post_init__
self.markdown = "\n\n".join(self.split(source))
File "./test-mkapi/.env/lib/python3.7/site-packages/mkapi/core/page.py", line 58, in split
inherit_by_filters(node, filters)
File "./test-mkapi/.env/lib/python3.7/site-packages/mkapi/core/inherit.py", line 121, in inherit_by_filters
inherit(node, strict=True)
File "./test-mkapi/.env/lib/python3.7/site-packages/mkapi/core/inherit.py", line 92, in inherit
for base in bases:
File "./test-mkapi/.env/lib/python3.7/site-packages/mkapi/core/inherit.py", line 111, in gen
yield get_node(getattr(base, name))
File "./test-mkapi/.env/lib/python3.7/site-packages/mkapi/core/node.py", line 169, in get_node
return _get_node(obj)
File "./test-mkapi/.env/lib/python3.7/site-packages/mkapi/core/node.py", line 154, in _get_node
return Node(obj)
File "<string>", line 4, in __init__
File "./test-mkapi/.env/lib/python3.7/site-packages/mkapi/core/node.py", line 25, in __post_init__
super().__post_init__()
File "./test-mkapi/.env/lib/python3.7/site-packages/mkapi/core/tree.py", line 37, in __post_init__
prefix, name = split_prefix_and_name(obj)
File "./test-mkapi/.env/lib/python3.7/site-packages/mkapi/core/object.py", line 98, in split_prefix_and_name
module = obj.__module__
AttributeError: 'method-wrapper' object has no attribute '__module__'
if i remove the inheritance or uncomment the call method it doesn't throw the error.
edit:
- it doesn't matter if the
__call__
-method has a docstring or not. - seems that the
__call__
method must be defined in all parent classes - it seems in 0.7.5 all dunder methods are added not regarding if they containing doc string
daizutabi commented
daizutabi commented
I reproduced the error by ![mkapi](foobar.Bar|strict)
.
Some dunder methods seem to cause this problem.
I'm going to check the code.
daizutabi commented
Two problems were solved in Version 0.7.6.
- AttributeError in
inherit()
function. - Dunder methods are added not regarding if they containing doc string.
Ahrak commented
thx, now it is working as excpected.