Skip to content

Commit

Permalink
Fix remaining type-hints
Browse files Browse the repository at this point in the history
Also renamed the "task" variable within run() as that was shadowing the
argument for "task"
  • Loading branch information
ogenstad committed Jun 14, 2024
1 parent 93f9339 commit 94ba774
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
22 changes: 11 additions & 11 deletions nornir/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -111,15 +111,15 @@ 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,
name=name,
processors=self.processors,
**kwargs,
)
self.processors.task_started(task)
self.processors.task_started(run_task)

run_on = []
if on_good:
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 94ba774

Please sign in to comment.