diff --git a/nornir/core/__init__.py b/nornir/core/__init__.py index eaa63c83..61923727 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 @@ -46,7 +47,7 @@ def __init__( self.inventory = inventory self.config = config or Config() self.processors = processors or Processors() - self.runner = runner + self._runner = runner def __enter__(self) -> "Nornir": return self @@ -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