From a19f4b05a933eae2138a7e3bd0ca809b87c045df Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Mon, 28 Aug 2023 17:11:19 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Add=20strict=20typing=20for=20`s?= =?UTF-8?q?phinx=5Fneeds.roles.need=5Fpart`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 1 - sphinx_needs/roles/need_part.py | 11 ++++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 4834aea31..295effed8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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', diff --git a/sphinx_needs/roles/need_part.py b/sphinx_needs/roles/need_part.py index f9b37e07a..0246069ce 100644 --- a/sphinx_needs/roles/need_part.py +++ b/sphinx_needs/roles/need_part.py @@ -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 @@ -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) @@ -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):