From 91799e8bbd69b36f85ce425a29fc8046c5e81105 Mon Sep 17 00:00:00 2001 From: Ben Dichter Date: Sat, 31 Aug 2024 20:14:34 -0400 Subject: [PATCH] clean up imports a bit (#498) * clean up imports a bit * stay away from private modules * use Type when indicating that an arg should be a class * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * * make static methods static --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- src/nwbinspector/_configuration.py | 4 +--- src/nwbinspector/_formatting.py | 6 ++++-- src/nwbinspector/_inspection.py | 8 ++++---- tests/streaming_tests.py | 3 ++- tests/test_inspector.py | 3 ++- tests/unit_tests/test_nwb_containers.py | 3 +-- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/nwbinspector/_configuration.py b/src/nwbinspector/_configuration.py index 18242d132..c1519439a 100644 --- a/src/nwbinspector/_configuration.py +++ b/src/nwbinspector/_configuration.py @@ -8,9 +8,7 @@ import jsonschema import yaml -from nwbinspector.utils._utils import ( - PathType, -) +from nwbinspector.utils import PathType from . import available_checks from ._registration import Importance diff --git a/src/nwbinspector/_formatting.py b/src/nwbinspector/_formatting.py index 2b6cdc228..712077ddd 100644 --- a/src/nwbinspector/_formatting.py +++ b/src/nwbinspector/_formatting.py @@ -106,7 +106,8 @@ def __init__( self.message_counter = 0 self.formatted_messages = [] - def _count_messages_by_importance(self, messages: List[InspectorMessage]) -> Dict[str, int]: + @staticmethod + def _count_messages_by_importance(messages: List[InspectorMessage]) -> Dict[str, int]: message_count_by_importance = {importance_level.name: 0 for importance_level in Importance} for message in messages: message_count_by_importance[message.importance.name] += 1 @@ -114,7 +115,8 @@ def _count_messages_by_importance(self, messages: List[InspectorMessage]) -> Dic message_count_by_importance.pop(key) return message_count_by_importance - def _get_name(self, obj) -> str: + @staticmethod + def _get_name(obj) -> str: if isinstance(obj, Enum): return obj.name if isinstance(obj, str): diff --git a/src/nwbinspector/_inspection.py b/src/nwbinspector/_inspection.py index 6955f02d6..b48f1dbc9 100644 --- a/src/nwbinspector/_inspection.py +++ b/src/nwbinspector/_inspection.py @@ -6,7 +6,7 @@ from collections import defaultdict from concurrent.futures import ProcessPoolExecutor, as_completed from pathlib import Path -from typing import Iterable, List, Optional, Union +from typing import Iterable, List, Optional, Type, Union from warnings import filterwarnings, warn import pynwb @@ -37,7 +37,7 @@ def inspect_all( n_jobs: int = 1, skip_validate: bool = False, progress_bar: bool = True, - progress_bar_class: tqdm = tqdm, + progress_bar_class: Type[tqdm] = tqdm, progress_bar_options: Optional[dict] = None, stream: bool = False, version_id: Optional[str] = None, @@ -421,7 +421,7 @@ def inspect_nwbfile_object( def run_checks( nwbfile: pynwb.NWBFile, checks: list, - progress_bar_class: Optional[tqdm] = None, + progress_bar_class: Optional[Type[tqdm]] = None, progress_bar_options: Optional[dict] = None, ) -> Iterable[InspectorMessage]: """ @@ -435,7 +435,7 @@ def run_checks( The list of check functions that will be run on the in-memory pynwb.NWBFile object. progress_bar_class : type of tqdm.tqdm, optional The specific child class of tqdm.tqdm to use to make progress bars. - Defaults to not displaying progress per set of checks over an invidiual file. + Defaults to not displaying progress per set of checks over an individual file. progress_bar_options : dict, optional Dictionary of keyword arguments to pass directly to the `progress_bar_class`. diff --git a/tests/streaming_tests.py b/tests/streaming_tests.py index f4e12223c..6289caa8f 100644 --- a/tests/streaming_tests.py +++ b/tests/streaming_tests.py @@ -64,7 +64,8 @@ def setUpClass(cls): def tearDownClass(cls): rmtree(cls.tempdir) - def assertFileExists(self, path: FilePathType): + @staticmethod + def assertFileExists(path: FilePathType): path = Path(path) assert path.exists() diff --git a/tests/test_inspector.py b/tests/test_inspector.py index 3f17f7c1b..50b7defb2 100644 --- a/tests/test_inspector.py +++ b/tests/test_inspector.py @@ -88,7 +88,8 @@ def add_simple_table(nwbfile: NWBFile): class TestInspector(TestCase): """A common helper class for testing the NWBInspector.""" - def assertFileExists(self, path: FilePathType): + @staticmethod + def assertFileExists(path: FilePathType): path = Path(path) assert path.exists() diff --git a/tests/unit_tests/test_nwb_containers.py b/tests/unit_tests/test_nwb_containers.py index 29a260f62..89142d556 100644 --- a/tests/unit_tests/test_nwb_containers.py +++ b/tests/unit_tests/test_nwb_containers.py @@ -9,8 +9,7 @@ from pynwb import NWBContainer, NWBFile from pynwb.image import ImageSeries -from nwbinspector import Importance, InspectorMessage -from nwbinspector._registration import Severity +from nwbinspector import Importance, InspectorMessage, Severity from nwbinspector.checks import ( check_empty_string_for_optional_attribute, check_large_dataset_compression,