diff --git a/nornir/core/__init__.py b/nornir/core/__init__.py index eaa63c83..8dbf1fd2 100644 --- a/nornir/core/__init__.py +++ b/nornir/core/__init__.py @@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Any, Callable, Dict, Generator, List, Optional, Type from nornir.core.configuration import Config +from nornir.core.exceptions import PluginNotRegistered from nornir.core.inventory import Inventory from nornir.core.plugins.runners import RunnerPlugin from nornir.core.processor import Processor, Processors @@ -142,7 +143,7 @@ def run( else: logger.warning("Task %r has not been run – 0 hosts selected", task.name) - result = self.runner.run(task, run_on) + result = self._runner.run(task, run_on) raise_on_error = ( raise_on_error @@ -168,6 +169,13 @@ def close_connections_task(task): self.run(task=close_connections_task, on_good=on_good, on_failed=on_failed) + @property + def _runner(self) -> RunnerPlugin: + if self.runner: + return self.runner + + raise PluginNotRegistered("Runner plugin not registered") + @classmethod def get_validators(cls) -> Generator[Callable[["Nornir"], "Nornir"], None, None]: yield cls.validate diff --git a/setup.cfg b/setup.cfg index bc69f979..656cba83 100644 --- a/setup.cfg +++ b/setup.cfg @@ -48,7 +48,6 @@ warn_redundant_casts = True [mypy-nornir.core] disallow_untyped_defs = False disallow_incomplete_defs = False -strict_optional = False [mypy-tests.*] ignore_errors = True