Skip to content

Commit

Permalink
Merge pull request #819 from 2bndy5/type-check-pygments
Browse files Browse the repository at this point in the history
Type check pygments and limit docutils stub version
  • Loading branch information
michaeljones authored Mar 2, 2022
2 parents 96b8a39 + 9cc01b1 commit 20f892f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
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]:
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

0 comments on commit 20f892f

Please sign in to comment.