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

Adding docs from a package that is installed fails with KeyError: <class 'ast.BoolOp'> #82

Closed
galwiner opened this issue Jun 6, 2022 · 7 comments

Comments

@galwiner
Copy link

galwiner commented Jun 6, 2022

I added a package to my poetry dependency list using pip add <package_name>
I then try to add the package to documentation using ::: package_name inside package_docs.md

When I run mkdocs serve I get an error message:

ERROR    -  Error reading page 'paramstore\api.md': <class 'ast.BoolOp'>
Traceback (most recent call last):
  File "C:\Users\gal\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\gal\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "c:\my_repo\.venv\Scripts\mkdocs.exe\__main__.py", line 7, in <module>
  File "c:\my_repo\.venv\lib\site-packages\click\core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "c:\my_repo\.venv\lib\site-packages\click\core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "c:\my_repo\.venv\lib\site-packages\click\core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "c:\my_repo\.venv\lib\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\my_repo\.venv\lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "c:\my_repo\.venv\lib\site-packages\mkdocs\__main__.py", line 192, in build_command
    build.build(config.load_config(**kwargs), dirty=not clean)
  File "c:\my_repo\.venv\lib\site-packages\mkdocs\commands\build.py", line 292, in build
    _populate_page(file.page, config, files, dirty)
  File "c:\my_repo\.venv\lib\site-packages\mkdocs\commands\build.py", line 174, in _populate_page
    page.render(config, files)
  File "c:\my_repo\.venv\lib\site-packages\mkdocs\structure\pages.py", line 175, in render
    self.content = md.convert(self.markdown)
  File "c:\my_repo\.venv\lib\site-packages\markdown\core.py", line 264, in convert
    root = self.parser.parseDocument(self.lines).getroot()
  File "c:\my_repo\.venv\lib\site-packages\markdown\blockparser.py", line 90, in parseDocument
    self.parseChunk(self.root, '\n'.join(lines))
  File "c:\my_repo\.venv\lib\site-packages\markdown\blockparser.py", line 105, in parseChunk
    self.parseBlocks(parent, text.split('\n\n'))
  File "c:\my_repo\.venv\lib\site-packages\markdown\blockparser.py", line 123, in parseBlocks
    if processor.run(parent, blocks) is not False:
  File "c:\my_repo\.venv\lib\site-packages\mkdocstrings\extension.py", line 121, in run
    html, handler, data = self._process_block(identifier, block, heading_level)
  File "c:\my_repo\.venv\lib\site-packages\mkdocstrings\extension.py", line 195, in _process_block
    data: CollectorItem = handler.collect(identifier, options)
  File "c:\my_repo\.venv\lib\site-packages\mkdocstrings_handlers\python\handler.py", line 191, in collect
    loader.load_module(module_name)
  File "c:\my_repo\.venv\lib\site-packages\griffe\loader.py", line 148, in load_module
    top_module = self._load_module(package.name, package.path, submodules=submodules)
  File "c:\my_repo\.venv\lib\site-packages\griffe\loader.py", line 352, in _load_module
    return self._load_module_path(module_name, module_path, submodules, parent)
  File "c:\my_repo\.venv\lib\site-packages\griffe\loader.py", line 380, in _load_module_path
    self._load_submodules(module)
  File "c:\my_repo\.venv\lib\site-packages\griffe\loader.py", line 385, in _load_submodules
    self._load_submodule(module, subparts, subpath)
  File "c:\my_repo\.venv\lib\site-packages\griffe\loader.py", line 396, in _load_submodule
    member_parent[subparts[-1]] = self._load_module(
  File "c:\my_repo\.venv\lib\site-packages\griffe\loader.py", line 352, in _load_module
    return self._load_module_path(module_name, module_path, submodules, parent)
  File "c:\my_repo\.venv\lib\site-packages\griffe\loader.py", line 374, in _load_module_path
    module = self._visit_module(code, module_name, module_path, parent)
  File "c:\my_repo\.venv\lib\site-packages\griffe\loader.py", line 413, in _visit_module
    module = visit(
  File "c:\my_repo\.venv\lib\site-packages\griffe\agents\visitor.py", line 92, in visit
    return Visitor(
  File "c:\my_repo\.venv\lib\site-packages\griffe\agents\visitor.py", line 172, in get_module
    self.visit(top_node)
  File "c:\my_repo\.venv\lib\site-packages\griffe\agents\visitor.py", line 183, in visit
    super().visit(node)
  File "c:\my_repo\.venv\lib\site-packages\griffe\agents\base.py", line 19, in visit
    getattr(self, f"visit_{node.kind}", self.generic_visit)(node)  # type: ignore[attr-defined]
  File "c:\my_repo\.venv\lib\site-packages\griffe\agents\visitor.py", line 214, in visit_module
    self.generic_visit(node)
  File "c:\my_repo\.venv\lib\site-packages\griffe\agents\visitor.py", line 196, in generic_visit
    self.visit(child)
  File "c:\my_repo\.venv\lib\site-packages\griffe\agents\visitor.py", line 183, in visit
    super().visit(node)
  File "c:\my_repo\.venv\lib\site-packages\griffe\agents\base.py", line 19, in visit
    getattr(self, f"visit_{node.kind}", self.generic_visit)(node)  # type: ignore[attr-defined]
  File "c:\my_repo\.venv\lib\site-packages\griffe\agents\visitor.py", line 451, in visit_functiondef
    self.handle_function(node)
  File "c:\my_repo\.venv\lib\site-packages\griffe\agents\visitor.py", line 416, in handle_function
    returns=get_annotation(node.returns, parent=self.current),
  File "c:\my_repo\.venv\lib\site-packages\griffe\agents\nodes.py", line 764, in get_annotation
    return _get_annotation(node, parent)
  File "c:\my_repo\.venv\lib\site-packages\griffe\agents\nodes.py", line 749, in _get_annotation
    return _node_annotation_map[type(node)](node, parent)
KeyError: <class 'ast.BoolOp'>
@pawamoy
Copy link
Member

pawamoy commented Jun 6, 2022

Is the package public? I'd like to see the source 🙂
If not, that's fine, I can still work on a fix.

@galwiner
Copy link
Author

galwiner commented Jun 6, 2022

Sure! It's entropylab (pip install entropylab)

We were able to trace the problem to the an incorrect type annotation on our side. Just took a bit of time to find where it was as the error message gave no hint.

@pawamoy
Copy link
Member

pawamoy commented Jun 6, 2022

OK. I'll try to catch the exception to provide such a hint. Out of curiosity, what did the annotation look like?

@aschmu
Copy link

aschmu commented Jun 19, 2022

I also have the same problem after upgrading to python 3.8 and mkdocstrings[python]

@aschmu
Copy link

aschmu commented Jun 19, 2022

I tried a workaround using mkdocstrings[python-legacy] with pytkdocs[numpy-style] but my docstrings aren't getting parsed correctly for some reason.

@pawamoy
Copy link
Member

pawamoy commented Jun 26, 2022

@aschmu, it's probably wrong to use boolean operations in annotations (a and b, a or b). Try to see if you have such an annotation somewhere.

@pawamoy
Copy link
Member

pawamoy commented Jun 27, 2022

Next version will log an error instead of crashing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants