Skip to content

Commit

Permalink
🔧 Add strict typing for sphinx_needs.roles.need_part
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell committed Aug 28, 2023
1 parent 741f565 commit a19f4b0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ module = [
'sphinx_needs.functions.functions',
'sphinx_needs.layout',
'sphinx_needs.needsfile',
'sphinx_needs.roles.need_part',
'sphinx_needs.roles.need_ref',
'sphinx_needs.services.github',
'sphinx_needs.utils',
Expand Down
11 changes: 6 additions & 5 deletions sphinx_needs/roles/need_part.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@
"""
import hashlib
import re
from typing import List
from typing import List, cast

from docutils import nodes
from sphinx.application import Sphinx
from sphinx.environment import BuildEnvironment

from sphinx_needs.data import NeedsInfoType
from sphinx_needs.logging import get_logger
from sphinx_needs.utils import unwrap

log = get_logger(__name__)


class NeedPart(nodes.Inline, nodes.Element):
class NeedPart(nodes.Inline, nodes.Element): # type: ignore
pass


Expand All @@ -31,11 +32,11 @@ def process_need_part(app: Sphinx, doctree: nodes.document, fromdocname: str, fo
part_pattern = re.compile(r"\(([\w-]+)\)(.*)")


def update_need_with_parts(env: BuildEnvironment, need, part_nodes: List[NeedPart]) -> None:
def update_need_with_parts(env: BuildEnvironment, need: NeedsInfoType, part_nodes: List[NeedPart]) -> None:
app = unwrap(env.app)
builder = unwrap(app.builder)
for part_node in part_nodes:
content = part_node.children[0].children[0] # ->inline->Text
content = cast(str, part_node.children[0].children[0]) # ->inline->Text
result = part_pattern.match(content)
if result:
inline_id = result.group(1)
Expand Down Expand Up @@ -85,7 +86,7 @@ def update_need_with_parts(env: BuildEnvironment, need, part_nodes: List[NeedPar
part_node.append(node_need_part_line)


def find_parts(node: nodes.Element) -> List[NeedPart]:
def find_parts(node: nodes.Node) -> List[NeedPart]:
found_nodes = []
for child in node.children:
if isinstance(child, NeedPart):
Expand Down

0 comments on commit a19f4b0

Please sign in to comment.