From ede8624dc62dd2966973735f2c476ff34b9bc967 Mon Sep 17 00:00:00 2001 From: rettigl Date: Fri, 22 Mar 2024 23:13:24 +0100 Subject: [PATCH] add linter options to check for unused arguments and variables, and add corresponding ignores --- pyproject.toml | 3 +++ sed/calibrator/energy.py | 4 ++-- sed/calibrator/momentum.py | 10 +++++----- sed/loader/flash/loader.py | 9 ++++----- sed/loader/generic/loader.py | 20 ++++++++++---------- sed/loader/mpes/loader.py | 2 +- sed/loader/sxp/loader.py | 6 +++--- tests/loader/flash/test_flash_metadata.py | 6 +++--- 8 files changed, 31 insertions(+), 29 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 94aac192..82e73b50 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -88,6 +88,9 @@ lint.select = [ "E", # pycodestyle "W", # pycodestyle "PL", # pylint + "F841", # unused variable + "F401", # unused imports + "ARG", # unused arguments ] lint.ignore = [ "E701", # Multiple statements on one line (colon) diff --git a/sed/calibrator/energy.py b/sed/calibrator/energy.py index f980059c..7e6c81f7 100644 --- a/sed/calibrator/energy.py +++ b/sed/calibrator/energy.py @@ -408,7 +408,7 @@ def update(refid, ranges): ranges=ranges_slider, ) - def apply_func(apply: bool): # pylint: disable=unused-argument + def apply_func(apply: bool): # noqa: ARG001 self.add_ranges( ranges_slider.value, refid_slider.value, @@ -1141,7 +1141,7 @@ def update(amplitude, x_center, y_center, **kwds): fig.canvas.draw_idle() - def common_apply_func(apply: bool): # pylint: disable=unused-argument + def common_apply_func(apply: bool): # noqa: ARG001 self.correction = {} self.correction["amplitude"] = correction["amplitude"] self.correction["center"] = correction["center"] diff --git a/sed/calibrator/momentum.py b/sed/calibrator/momentum.py index a9499c53..60cb6627 100644 --- a/sed/calibrator/momentum.py +++ b/sed/calibrator/momentum.py @@ -258,7 +258,7 @@ def update(plane: int, width: int): width=width_slider, ) - def apply_fun(apply: bool): # pylint: disable=unused-argument + def apply_fun(apply: bool): # noqa: ARG001 start = plane_slider.value stop = plane_slider.value + width_slider.value @@ -541,7 +541,7 @@ def onclick(event): cid = fig.canvas.mpl_connect("button_press_event", onclick) - def apply_func(apply: bool): # pylint: disable=unused-argument + def apply_func(apply: bool): # noqa: ARG001 fig.canvas.mpl_disconnect(cid) point_no_input.close() @@ -1144,7 +1144,7 @@ def update(scale: float, xtrans: float, ytrans: float, angle: float): angle=angle_slider, ) - def apply_func(apply: bool): # pylint: disable=unused-argument + def apply_func(apply: bool): # noqa: ARG001 if transformations.get("scale", 1) != 1: self.coordinate_transform( transform_type="scaling", @@ -1457,7 +1457,7 @@ def update( point_a_y: int, point_b_x: int, point_b_y: int, - k_distance: float, # pylint: disable=unused-argument + k_distance: float, # noqa: ARG001 ): fig.canvas.draw_idle() marker_a.set_xdata(point_a_x) @@ -1493,7 +1493,7 @@ def onclick(event): cid = fig.canvas.mpl_connect("button_press_event", onclick) - def apply_func(apply: bool): # pylint: disable=unused-argument + def apply_func(apply: bool): # noqa: ARG001 point_a = [point_a_input_x.value, point_a_input_y.value] point_b = [point_b_input_x.value, point_b_input_y.value] calibration = self.calibrate( diff --git a/sed/loader/flash/loader.py b/sed/loader/flash/loader.py index 6e1afd97..0ae1b4a4 100644 --- a/sed/loader/flash/loader.py +++ b/sed/loader/flash/loader.py @@ -750,7 +750,6 @@ def parquet_handler( load_parquet: bool = False, save_parquet: bool = False, force_recreate: bool = False, - **kwds, ) -> Tuple[dd.DataFrame, dd.DataFrame]: """ Handles loading and saving of parquet files based on the provided parameters. @@ -836,7 +835,7 @@ def parquet_handler( return dataframe_electron, dataframe_pulse - def parse_metadata(self, scicat_token: str = None, **kwds) -> dict: + def parse_metadata(self, scicat_token: str = None) -> dict: """Uses the MetadataRetriever class to fetch metadata from scicat for each run. Returns: @@ -854,12 +853,12 @@ def parse_metadata(self, scicat_token: str = None, **kwds) -> dict: def get_count_rate( self, - fids: Sequence[int] = None, - **kwds, + fids: Sequence[int] = None, # noqa: ARG002 + **kwds, # noqa: ARG002 ): return None, None - def get_elapsed_time(self, fids=None, **kwds): + def get_elapsed_time(self, fids=None, **kwds): # noqa: ARG002 return None def read_dataframe( diff --git a/sed/loader/generic/loader.py b/sed/loader/generic/loader.py index 7eb92e72..f3cd5f25 100644 --- a/sed/loader/generic/loader.py +++ b/sed/loader/generic/loader.py @@ -101,10 +101,10 @@ def read_dataframe( def get_files_from_run_id( self, - run_id: str, - folders: Union[str, Sequence[str]] = None, - extension: str = None, - **kwds, + run_id: str, # noqa: ARG002 + folders: Union[str, Sequence[str]] = None, # noqa: ARG002 + extension: str = None, # noqa: ARG002 + **kwds, # noqa: ARG002 ) -> List[str]: """Locate the files for a given run identifier. @@ -120,10 +120,10 @@ def get_files_from_run_id( """ raise NotImplementedError - def get_count_rate( # Pylint: disable=unused_parameter + def get_count_rate( self, - fids: Sequence[int] = None, - **kwds, + fids: Sequence[int] = None, # noqa: ARG002 + **kwds, # noqa: ARG002 ) -> Tuple[np.ndarray, np.ndarray]: """Create count rate data for the files specified in ``fids``. @@ -139,10 +139,10 @@ def get_count_rate( # Pylint: disable=unused_parameter # TODO return None, None - def get_elapsed_time( # Pylint: disable=unused_parameter + def get_elapsed_time( self, - fids: Sequence[int] = None, - **kwds, + fids: Sequence[int] = None, # noqa: ARG002 + **kwds, # noqa: ARG002 ) -> float: """Return the elapsed time in the files specified in ``fids``. diff --git a/sed/loader/mpes/loader.py b/sed/loader/mpes/loader.py index 11c7b9b4..1793a300 100644 --- a/sed/loader/mpes/loader.py +++ b/sed/loader/mpes/loader.py @@ -634,7 +634,7 @@ def get_files_from_run_id( run_id: str, folders: Union[str, Sequence[str]] = None, extension: str = "h5", - **kwds, + **kwds, # noqa: ARG002 ) -> List[str]: """Locate the files for a given run identifier. diff --git a/sed/loader/sxp/loader.py b/sed/loader/sxp/loader.py index ce89e546..67faca4c 100644 --- a/sed/loader/sxp/loader.py +++ b/sed/loader/sxp/loader.py @@ -898,12 +898,12 @@ def gather_metadata(self, metadata: dict = None) -> dict: def get_count_rate( self, - fids: Sequence[int] = None, - **kwds, + fids: Sequence[int] = None, # noqa: ARG002 + **kwds, # noqa: ARG002 ): return None, None - def get_elapsed_time(self, fids=None, **kwds): + def get_elapsed_time(self, fids=None, **kwds): # noqa: ARG002 return None def read_dataframe( diff --git a/tests/loader/flash/test_flash_metadata.py b/tests/loader/flash/test_flash_metadata.py index eee1e9d8..ef5305ad 100644 --- a/tests/loader/flash/test_flash_metadata.py +++ b/tests/loader/flash/test_flash_metadata.py @@ -11,7 +11,7 @@ def mock_requests(requests_mock): # Test cases for MetadataRetriever -def test_get_metadata(mock_requests): +def test_get_metadata(mock_requests): # noqa: ARG001 metadata_config = { "scicat_url": "https://example.com", "scicat_token": "fake_token", @@ -22,7 +22,7 @@ def test_get_metadata(mock_requests): assert metadata == {"fake": "data"} -def test_get_metadata_with_existing_metadata(mock_requests): +def test_get_metadata_with_existing_metadata(mock_requests): # noqa: ARG001 metadata_config = { "scicat_url": "https://example.com", "scicat_token": "fake_token", @@ -34,7 +34,7 @@ def test_get_metadata_with_existing_metadata(mock_requests): assert metadata == {"existing": "metadata", "fake": "data"} -def test_get_metadata_per_run(mock_requests): +def test_get_metadata_per_run(mock_requests): # noqa: ARG001 metadata_config = { "scicat_url": "https://example.com", "scicat_token": "fake_token",