Skip to content

Commit

Permalink
🔧 Add strict typing for sphinx_needs.directives.needpie
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell committed Aug 28, 2023
1 parent fb8fda9 commit 9a2577d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Expand Up @@ -89,6 +89,8 @@ namespace_packages = true

[[tool.mypy.overrides]]
module = [
"matplotlib.*",
"numpy.*",
"requests_file",
"sphinx_data_viewer.*",
"sphinxcontrib.plantuml.*",
Expand All @@ -102,7 +104,6 @@ module = [
'sphinx_needs.directives.need',
'sphinx_needs.directives.needbar',
'sphinx_needs.directives.needextend',
'sphinx_needs.directives.needpie',
'sphinx_needs.directives.needuml',
'sphinx_needs.functions.functions',
'sphinx_needs.layout',
Expand Down
2 changes: 1 addition & 1 deletion sphinx_needs/directives/needpie.py
Expand Up @@ -154,7 +154,7 @@ def process_needpie(app: Sphinx, doctree: nodes.document, fromdocname: str, foun
elif current_needpie["filter_func"] and not content:
try:
# check and get filter_func
filter_func, filter_args = check_and_get_external_filter_func(current_needpie)
filter_func, filter_args = check_and_get_external_filter_func(current_needpie.get("filter_func"))
# execute filter_func code
# Provides only a copy of needs to avoid data manipulations.
context = {
Expand Down
2 changes: 1 addition & 1 deletion sphinx_needs/filter_common.py
Expand Up @@ -127,7 +127,7 @@ def process_filters(
all_needs_incl_parts = prepare_need_list(checked_all_needs)

# Check if external filter code is defined
filter_func, filter_args = check_and_get_external_filter_func(filter_data)
filter_func, filter_args = check_and_get_external_filter_func(filter_data.get("filter_func"))

filter_code = None
# Get filter_code from
Expand Down
6 changes: 2 additions & 4 deletions sphinx_needs/utils.py
Expand Up @@ -14,7 +14,7 @@
from sphinx.application import BuildEnvironment, Sphinx

from sphinx_needs.config import NeedsSphinxConfig
from sphinx_needs.data import NeedsFilteredBaseType, NeedsInfoType, SphinxNeedsData
from sphinx_needs.data import NeedsInfoType, SphinxNeedsData
from sphinx_needs.defaults import NEEDS_PROFILING
from sphinx_needs.logging import get_logger

Expand Down Expand Up @@ -304,14 +304,12 @@ def check_and_calc_base_url_rel_path(external_url: str, fromdocname: str) -> str
return ref_uri


def check_and_get_external_filter_func(filter_data: NeedsFilteredBaseType):
def check_and_get_external_filter_func(filter_func_ref: Optional[str]):
"""Check and import filter function from external python file."""
# Check if external filter code is defined
filter_func = None
filter_args = []

filter_func_ref = filter_data.get("filter_func")

if filter_func_ref:
try:
filter_module, filter_function = filter_func_ref.rsplit(".")
Expand Down

0 comments on commit 9a2577d

Please sign in to comment.