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

Type check pygments and limit docutils stub version #819

Merged
merged 3 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions breathe/filetypes.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
"""
A module to house the methods for resolving a code-blocks language based on filename
(and extension).
"""
from typing import Optional
import os.path

import pygments # type: ignore
from pygments.lexers import get_lexer_for_filename
from pygments.util import ClassNotFound


def get_pygments_alias(filename: str) -> Optional[str]:
"Find first pygments alias from filename"
try:
lexer_cls = pygments.lexers.get_lexer_for_filename(filename)
return lexer_cls.aliases[0]
except pygments.util.ClassNotFound:
lexer_cls = get_lexer_for_filename(filename)
return lexer_cls.aliases[0] # type: ignore
except ClassNotFound:
return None


Expand All @@ -20,5 +25,5 @@ def get_extension(filename: str) -> str:
(first, second) = os.path.splitext(filename)

# Doxygen allows users to specify the file extension ".unparsed" to disable syntax highlighting.
# We translate it into the pygments unhighlighted 'text' type
# We translate it into the pygments un-highlighted 'text' type
return (second or first).lstrip(".").replace("unparsed", "text")
4 changes: 2 additions & 2 deletions breathe/renderer/sphinxrenderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from sphinx.ext.graphviz import graphviz

from docutils import nodes
from docutils.nodes import Element, Node, TextElement
from docutils.nodes import Node, TextElement
from docutils.statemachine import StringList, UnexpectedIndentationError
from docutils.parsers.rst.states import Text

Expand Down Expand Up @@ -846,7 +846,7 @@ def run_domain_directive(self, kind, names):
signode.children = [n for n in signode.children if not n.tagname == "desc_addname"]
return nodes

def create_doxygen_target(self, node) -> List[Element]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still getting used to mypy. You've removed this because it can be inferred? Or something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be inferred. Repeatedly specifying the returned type seems more error prone.

def create_doxygen_target(self, node):
"""Can be overridden to create a target node which uses the doxygen refid information
which can be used for creating links between internal doxygen elements.

Expand Down
4 changes: 2 additions & 2 deletions breathe/renderer/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from docutils import nodes
from docutils.nodes import Element

from typing import Any, Dict, List
from typing import Any, Dict, List, Sequence


class TargetHandler:
def create_target(self, refid: str) -> List[Element]:
def create_target(self, refid: str) -> Sequence[Element]:
raise NotImplementedError


Expand Down
3 changes: 2 additions & 1 deletion requirements/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pip-tools>=0.3.5
pytest

mypy>=0.900
types-docutils>=0.17.0
types-docutils>=0.14,<0.18
types-Pygments

black==22.1.0