From a013a99f06d725bf32b53496b710a62655918e5b Mon Sep 17 00:00:00 2001 From: Patrick Ogenstad Date: Wed, 19 Jun 2024 14:05:50 +0200 Subject: [PATCH] Fix remaining type-hints (#924) Also renamed the "task" variable within run() as that was shadowing the argument for "task" Co-authored-by: David Barroso --- nornir/core/__init__.py | 22 +++++++++++----------- setup.cfg | 4 ---- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/nornir/core/__init__.py b/nornir/core/__init__.py index 18f9c618..b30f17b7 100644 --- a/nornir/core/__init__.py +++ b/nornir/core/__init__.py @@ -86,10 +86,10 @@ def filter(self, *args: Any, **kwargs: Any) -> "Nornir": def run( self, - task, - raise_on_error=None, - on_good=True, - on_failed=False, + task: Callable[..., Any], + raise_on_error: Optional[bool] = None, + on_good: bool = True, + on_failed: bool = False, name: Optional[str] = None, **kwargs: Any, ) -> AggregatedResult: @@ -111,7 +111,7 @@ def run( Returns: :obj:`nornir.core.task.AggregatedResult`: results of each execution """ - task = Task( + run_task = Task( task, self, global_dry_run=self.data.dry_run, @@ -119,7 +119,7 @@ def run( processors=self.processors, **kwargs, ) - self.processors.task_started(task) + self.processors.task_started(run_task) run_on = [] if on_good: @@ -135,14 +135,14 @@ def run( if num_hosts: logger.info( "Running task %r with args %s on %d hosts", - task.name, + run_task.name, kwargs, num_hosts, ) else: - logger.warning("Task %r has not been run – 0 hosts selected", task.name) + logger.warning("Task %r has not been run – 0 hosts selected", run_task.name) - result = self.runner.run(task, run_on) + result = self.runner.run(run_task, run_on) raise_on_error = ( raise_on_error @@ -154,7 +154,7 @@ def run( else: self.data.failed_hosts.update(result.failed_hosts.keys()) - self.processors.task_completed(task, result) + self.processors.task_completed(run_task, result) return result @@ -163,7 +163,7 @@ def dict(self) -> Dict[str, Any]: return {"data": self.data.dict(), "inventory": self.inventory.dict()} def close_connections(self, on_good: bool = True, on_failed: bool = False) -> None: - def close_connections_task(task): + def close_connections_task(task: Task) -> None: task.host.close_connections() self.run(task=close_connections_task, on_good=on_good, on_failed=on_failed) diff --git a/setup.cfg b/setup.cfg index 656cba83..3fd76670 100644 --- a/setup.cfg +++ b/setup.cfg @@ -45,9 +45,5 @@ warn_unused_ignores = True warn_return_any = True warn_redundant_casts = True -[mypy-nornir.core] -disallow_untyped_defs = False -disallow_incomplete_defs = False - [mypy-tests.*] ignore_errors = True