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

Does not parse Literal[-1] or other negative literals #71

Closed
gegnew opened this issue May 25, 2022 · 1 comment
Closed

Does not parse Literal[-1] or other negative literals #71

gegnew opened this issue May 25, 2022 · 1 comment

Comments

@gegnew
Copy link

gegnew commented May 25, 2022

Describe the bug
I have a constant in my package's base __init__.py like:

CONSTANT: Literal[-1] = -1
"""
docstring
"""

It's pulled into mkdocs through the doc_file.md in mkdocs.yml, and in doc_file.md with:

::: package.CONSTANT

I get an error when building or serving (error logs at bottom)

Expected behavior
package.CONSTANT: Literal[-1] = -1 in the docs

System (please complete the following information):

  • griffe version: 0.19.1

  • Python version: 3.9.12

  • OS: Linux

    ERROR    -  Error reading page 'api_client.md': <class 'ast.USub'>
    Traceback (most recent call last):
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/bin/mkdocs", line 8, in <module>
        sys.exit(cli())
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
        return self.main(*args, **kwargs)
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/click/core.py", line 1055, in main
        rv = self.invoke(ctx)
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
        return _process_result(sub_ctx.command.invoke(sub_ctx))
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
        return ctx.invoke(self.callback, **ctx.params)
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/click/core.py", line 760, in invoke
        return __callback(*args, **kwargs)
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/mkdocs/__main__.py", line 181, in serve_command
        serve.serve(dev_addr=dev_addr, livereload=livereload, watch=watch, **kwargs)
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/mkdocs/commands/serve.py", line 63, in serve
        config = builder()
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/mkdocs/commands/serve.py", line 58, in builder
        build(config, live_server=live_server, dirty=dirty)
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/mkdocs/commands/build.py", line 292, in build
        _populate_page(file.page, config, files, dirty)
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/mkdocs/commands/build.py", line 174, in _populate_page
        page.render(config, files)
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/mkdocs/structure/pages.py", line 175, in render
        self.content = md.convert(self.markdown)
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/markdown/core.py", line 264, in convert
        root = self.parser.parseDocument(self.lines).getroot()
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/markdown/blockparser.py", line 90, in parseDocument
        self.parseChunk(self.root, '\n'.join(lines))
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/markdown/blockparser.py", line 105, in parseChunk
        self.parseBlocks(parent, text.split('\n\n'))
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/markdown/blockparser.py", line 123, in parseBlocks
        if processor.run(parent, blocks) is not False:
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/mkdocstrings/extension.py", line 120, in run
        html, handler, data = self._process_block(identifier, block, heading_level)
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/mkdocstrings/extension.py", line 182, in _process_block
        data: CollectorItem = handler.collector.collect(identifier, selection)
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/mkdocstrings_handlers/python/collector.py", line 77, in collect
        loader.load_module(module_name)
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/griffe/loader.py", line 148, in load_module
        top_module = self._load_module(package.name, package.path, submodules=submodules)
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/griffe/loader.py", line 346, in _load_module
        return self._load_module_path(module_name, module_path, submodules, parent)
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/griffe/loader.py", line 368, in _load_module_path
        module = self._visit_module(code, module_name, module_path, parent)
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/griffe/loader.py", line 407, in _visit_module
        module = visit(
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/griffe/agents/visitor.py", line 92, in visit
        return Visitor(
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/griffe/agents/visitor.py", line 172, in get_module
        self.visit(top_node)
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/griffe/agents/visitor.py", line 183, in visit
        super().visit(node)
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/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 "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/griffe/agents/visitor.py", line 214, in visit_module
        self.generic_visit(node)
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/griffe/agents/visitor.py", line 196, in generic_visit
        self.visit(child)
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/griffe/agents/visitor.py", line 183, in visit
        super().visit(node)
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/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 "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/griffe/agents/visitor.py", line 597, in visit_annassign
        self.handle_attribute(node, get_annotation(node.annotation, parent=self.current))
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/griffe/agents/nodes.py", line 754, in get_annotation
        return _get_annotation(node, parent)
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/griffe/agents/nodes.py", line 739, in _get_annotation
        return _node_annotation_map[type(node)](node, parent)
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/griffe/agents/nodes.py", line 679, in _get_subscript_annotation
        subscript = _get_annotation(node.slice, parent)
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/griffe/agents/nodes.py", line 739, in _get_annotation
        return _node_annotation_map[type(node)](node, parent)
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/griffe/agents/nodes.py", line 688, in _get_unaryop_annotation
        return Expression(_get_annotation(node.op, parent), _get_annotation(node.operand, parent))
      File "/home/g/Desktop/primity/cellengine-python-toolkit/.direnv/python-3.9.12/lib/python3.9/site-packages/griffe/agents/nodes.py", line 739, in _get_annotation
        return _node_annotation_map[type(node)](node, parent)
    KeyError: <class 'ast.USub'>
    
@pawamoy
Copy link
Member

pawamoy commented May 26, 2022

Hi, thanks for the report, this should be fixed in 0.19.3 🙂

@pawamoy pawamoy closed this as completed May 26, 2022
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

2 participants