Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Failing on a class with __getattr__ method #45

Closed
xuhcc opened this issue Jun 10, 2020 · 3 comments
Closed

[BUG] Failing on a class with __getattr__ method #45

xuhcc opened this issue Jun 10, 2020 · 3 comments
Labels
bug Something isn't working module:loader

Comments

@xuhcc
Copy link

xuhcc commented Jun 10, 2020

Describe the bug

I upgraded to pytkdocs 0.5.1 and got this error:

ERROR   -  mkdocstrings.handlers.python: Collection failed: ('No route with that name.', '__wrapped__')
Traceback (most recent call last):
  File "/venv/lib/python3.8/site-packages/pytkdocs/cli.py", line 193, in main
    output = json.dumps(process_json(line))
  File "/venv/lib/python3.8/site-packages/pytkdocs/cli.py", line 114, in process_json
    return process_config(json.loads(json_input))
  File "/venv/lib/python3.8/site-packages/pytkdocs/cli.py", line 91, in process_config
    obj = loader.get_object_documentation(path, members)
  File "/venv/lib/python3.8/site-packages/pytkdocs/loader.py", line 230, in get_object_documentation
    root_object = self.get_module_documentation(leaf, members)
  File "/venv/lib/python3.8/site-packages/pytkdocs/loader.py", line 311, in get_module_documentation
    root_object.add_child(self.get_module_documentation(leaf))
  File "/venv/lib/python3.8/site-packages/pytkdocs/loader.py", line 295, in get_module_documentation
    child_node = ObjectNode(member, member_name, parent=node)
  File "/venv/lib/python3.8/site-packages/pytkdocs/loader.py", line 43, in __init__
    self.obj: Any = inspect.unwrap(obj)
  File "/usr/lib/python3.8/inspect.py", line 520, in unwrap
    while _is_wrapper(func):
  File "/usr/lib/python3.8/inspect.py", line 511, in _is_wrapper
    return hasattr(f, '__wrapped__')
  File "/venv/lib/python3.8/site-packages/beancount/web/bottle_utils.py", line 25, in __getattr__
    return self.mapper_function(name)
  File "/venv/bin/bottle.py", line 409, in build
    if not builder: raise RouteBuildError("No route with that name.", _name)
bottle.RouteBuildError: ('No route with that name.', '__wrapped__')
 
ERROR   -  mkdocstrings.extension: Could not collect 'beancount.web' 
ERROR   -  Error reading page 'api_reference/beancount.web.md': ('No route with that name.', '__wrapped__') 
Traceback (most recent call last):
  File "build.py", line 52, in <module>
    sys.exit(cli())
  File "/venv/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/venv/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/venv/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/venv/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/venv/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/venv/lib/python3.8/site-packages/mkdocs/__main__.py", line 140, in serve_command
    serve.serve(
  File "/venv/lib/python3.8/site-packages/mkdocs/commands/serve.py", line 141, in serve
    config = builder()
  File "/venv/lib/python3.8/site-packages/mkdocs/commands/serve.py", line 136, in builder
    build(config, live_server=live_server, dirty=dirty)
  File "/venv/lib/python3.8/site-packages/mkdocs/commands/build.py", line 274, in build
    _populate_page(file.page, config, files, dirty)
  File "/venv/lib/python3.8/site-packages/mkdocs/commands/build.py", line 174, in _populate_page
    page.render(config, files)
  File "/venv/lib/python3.8/site-packages/mkdocs/structure/pages.py", line 183, in render
    self.content = md.convert(self.markdown)
  File "/venv/lib/python3.8/site-packages/markdown/core.py", line 263, in convert
    root = self.parser.parseDocument(self.lines).getroot()
  File "/venv/lib/python3.8/site-packages/markdown/blockparser.py", line 90, in parseDocument
    self.parseChunk(self.root, '\n'.join(lines))
  File "/venv/lib/python3.8/site-packages/markdown/blockparser.py", line 105, in parseChunk
    self.parseBlocks(parent, text.split('\n\n'))
  File "/venv/lib/python3.8/site-packages/markdown/blockparser.py", line 123, in parseBlocks
    if processor.run(parent, blocks) is not False:
  File "/venv/lib/python3.8/site-packages/mkdocstrings/extension.py", line 147, in run
    data: Any = handler.collector.collect(identifier, selection)
  File "/venv/lib/python3.8/site-packages/mkdocstrings/handlers/python.py", line 204, in collect
    raise CollectionError(result["error"])
mkdocstrings.handlers.CollectionError: ('No route with that name.', '__wrapped__')

Here's the relevant source code:

https://github.com/beancount/beancount/blob/2.3.0/beancount/web/bottle_utils.py#L24-L25

System (please complete the following information):

  • pytkdocs version: 0.5.1
  • Python version: 3.8
  • OS: Arch Linux
@pawamoy
Copy link
Member

pawamoy commented Jun 10, 2020

I'm always amazed by the flexibility of Python. inspect.unwrap calls hasattr on the object, triggering its __getattr__ method which in turn calls a mapper function that was passed to it, and defined in the bottle script I guess.

Well, I guess the obvious fix is to catch every exception when unwrapping:

try:
    member = inspect.unwrap(member)
except Exception:
    pass

Thanks for the report :)

I'll fix this and release asap

pawamoy added a commit that referenced this issue Jun 11, 2020
@pawamoy
Copy link
Member

pawamoy commented Jun 11, 2020

Released version 0.5.2 🙂

@pawamoy pawamoy closed this as completed Jun 11, 2020
@pawamoy pawamoy added bug Something isn't working module:loader labels Jun 11, 2020
@xuhcc
Copy link
Author

xuhcc commented Jun 11, 2020

Thank you! The problem is gone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working module:loader
Projects
None yet
Development

No branches or pull requests

2 participants