From 66591361a06305e34885d515e8694dbd13b5cf33 Mon Sep 17 00:00:00 2001 From: Patrick Ogenstad Date: Mon, 1 Jul 2024 09:12:38 +0200 Subject: [PATCH] Add missing return type annotation for special method `__init__ (#952) Fix Ruff - ANN204 --- nornir/core/exceptions.py | 2 +- nornir/core/task.py | 8 ++++---- pyproject.toml | 1 - tests/core/test_InitNornir.py | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/nornir/core/exceptions.py b/nornir/core/exceptions.py index 5a20e87d..0bf1bc66 100644 --- a/nornir/core/exceptions.py +++ b/nornir/core/exceptions.py @@ -75,7 +75,7 @@ class NornirSubTaskError(Exception): Raised by nornir when a sub task managed by :meth:`nornir.core.Task.run` has failed """ - def __init__(self, task: "Task", result: "Result"): + def __init__(self, task: "Task", result: "Result") -> None: self.task = task self.result = result diff --git a/nornir/core/task.py b/nornir/core/task.py index b7bb2f1d..3a53a6ca 100644 --- a/nornir/core/task.py +++ b/nornir/core/task.py @@ -48,7 +48,7 @@ def __init__( severity_level: int = DEFAULT_SEVERITY_LEVEL, parent_task: Optional["Task"] = None, **kwargs: str, - ): + ) -> None: self.task = task self.nornir = nornir self.name = name or task.__name__ @@ -214,7 +214,7 @@ def __init__( exception: Optional[BaseException] = None, severity_level: int = DEFAULT_SEVERITY_LEVEL, **kwargs: Any, - ): + ) -> None: self.result = result self.host = host self.changed = changed @@ -246,7 +246,7 @@ class MultiResult(List[Result]): a particular device/task. """ - def __init__(self, name: str): + def __init__(self, name: str) -> None: self.name = name def __getattr__(self, name: str) -> Any: @@ -280,7 +280,7 @@ class AggregatedResult(Dict[str, MultiResult]): You can access each individual result by doing ``my_aggr_result["hostname_of_device"]``. """ - def __init__(self, name: str, **kwargs: MultiResult): + def __init__(self, name: str, **kwargs: MultiResult) -> None: self.name = name super().__init__(**kwargs) diff --git a/pyproject.toml b/pyproject.toml index 16a83811..f727e821 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -150,7 +150,6 @@ ignore = [ # like this so that we can reactivate them one by one. Alternatively ignored after further # # investigation if they are deemed to not make sense. # ################################################################################################## - "ANN204", # Missing return type annotation for special method `__init__` "ANN401", # Dynamically typed expressions (typing.Any) are disallowed "ARG002", # Unused method argument "B028", # No explicit `stacklevel` keyword argument found diff --git a/tests/core/test_InitNornir.py b/tests/core/test_InitNornir.py index ba533b5a..745eab09 100644 --- a/tests/core/test_InitNornir.py +++ b/tests/core/test_InitNornir.py @@ -45,7 +45,7 @@ def transform_func_with_options(host, a): class InventoryTest: - def __init__(self, *args, **kwargs): + def __init__(self, *args, **kwargs) -> None: pass def load(self):