diff --git a/nornir/core/__init__.py b/nornir/core/__init__.py index 449f40ac..4146f3d8 100644 --- a/nornir/core/__init__.py +++ b/nornir/core/__init__.py @@ -14,7 +14,7 @@ logger = logging.getLogger(__name__) -class Nornir(object): +class Nornir: """ This is the main object to work with. It contains the inventory and it serves as task dispatcher. diff --git a/nornir/core/configuration.py b/nornir/core/configuration.py index 8b9a9ca7..357d9b30 100644 --- a/nornir/core/configuration.py +++ b/nornir/core/configuration.py @@ -50,7 +50,7 @@ def resolve(self, value: Optional[T]) -> T: return v -class SSHConfig(object): +class SSHConfig: __slots__ = ("config_file",) class Parameters: @@ -63,7 +63,7 @@ def dict(self) -> Dict[str, Any]: return {"config_file": self.config_file} -class InventoryConfig(object): +class InventoryConfig: __slots__ = "options", "plugin", "transform_function", "transform_function_options" class Parameters: @@ -97,7 +97,7 @@ def dict(self) -> Dict[str, Any]: } -class LoggingConfig(object): +class LoggingConfig: __slots__ = "enabled", "format", "level", "log_file", "loggers", "to_console" class Parameters: @@ -190,7 +190,7 @@ def configure(self) -> None: logger_.addHandler(stderr_handler) -class RunnerConfig(object): +class RunnerConfig: __slots__ = ("options", "plugin") class Parameters: @@ -210,7 +210,7 @@ def dict(self) -> Dict[str, Any]: } -class CoreConfig(object): +class CoreConfig: __slots__ = "raise_on_error" class Parameters: @@ -225,7 +225,7 @@ def dict(self) -> Dict[str, Any]: } -class Config(object): +class Config: __slots__ = ( "core", "inventory", diff --git a/nornir/core/filter.py b/nornir/core/filter.py index a4300cde..eb0db82a 100644 --- a/nornir/core/filter.py +++ b/nornir/core/filter.py @@ -3,7 +3,7 @@ from nornir.core.inventory import Host -class F_BASE(object): +class F_BASE: def __call__(self, host: Host) -> bool: raise NotImplementedError() diff --git a/nornir/core/inventory.py b/nornir/core/inventory.py index fcff2c76..f2615002 100644 --- a/nornir/core/inventory.py +++ b/nornir/core/inventory.py @@ -20,7 +20,7 @@ HostOrGroup = TypeVar("HostOrGroup", "Host", "Group") -class BaseAttributes(object): +class BaseAttributes: __slots__ = ("hostname", "password", "platform", "port", "username") def __init__( @@ -575,7 +575,7 @@ class FilterObj(Protocol): def __call__(self, host: Host, **kwargs: Any) -> bool: ... -class Inventory(object): +class Inventory: __slots__ = ("defaults", "groups", "hosts") def __init__( diff --git a/nornir/core/state.py b/nornir/core/state.py index 4e00e6d8..d04efee0 100644 --- a/nornir/core/state.py +++ b/nornir/core/state.py @@ -1,7 +1,7 @@ from typing import Any, Dict, Optional, Set -class GlobalState(object): +class GlobalState: """ This class is just a placeholder to share data amongst different versions of Nornir after running ``filter`` multiple times. diff --git a/nornir/core/task.py b/nornir/core/task.py index 27e61fd6..b7bb2f1d 100644 --- a/nornir/core/task.py +++ b/nornir/core/task.py @@ -14,7 +14,7 @@ DEFAULT_SEVERITY_LEVEL = logging.INFO -class Task(object): +class Task: """ A task is basically a wrapper around a function that has to be run against multiple devices. You won't probably have to deal with this class yourself as @@ -181,7 +181,7 @@ def is_dry_run(self, override: Optional[bool] = None) -> bool: return override if override is not None else self.global_dry_run -class Result(object): +class Result: """ Result of running individual tasks. diff --git a/pyproject.toml b/pyproject.toml index 229066f0..a28770b3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -167,7 +167,6 @@ ignore = [ "TRY004", # Prefer `TypeError` exception for invalid type "TRY300", # Consider moving this statement to an `else` block "TRY400", # Use `logging.exception` instead of `logging.error` - "UP004", # Class inherits from `object` "UP009", # UTF-8 encoding declaration is unnecessary "UP015", # Unnecessary open mode parameters "UP032", # Use f-string instead of `format` call diff --git a/tests/core/test_InitNornir.py b/tests/core/test_InitNornir.py index 3c0ba330..ba533b5a 100644 --- a/tests/core/test_InitNornir.py +++ b/tests/core/test_InitNornir.py @@ -61,7 +61,7 @@ def load(self): TransformFunctionRegister.register("transform_func_with_options", transform_func_with_options) -class Test(object): +class Test: def test_InitNornir_bare(self): os.chdir("tests/inventory_data/") nr = InitNornir() diff --git a/tests/core/test_configuration.py b/tests/core/test_configuration.py index 6d3b07a8..ce44de1e 100644 --- a/tests/core/test_configuration.py +++ b/tests/core/test_configuration.py @@ -9,7 +9,7 @@ DEFAULT_LOG_FORMAT = "%(asctime)s - %(name)12s - %(levelname)8s - %(funcName)10s() - %(message)s" -class Test(object): +class Test: def test_config_defaults(self): c = Config() assert c.dict() == { diff --git a/tests/core/test_connections.py b/tests/core/test_connections.py index 529b4369..1f773026 100644 --- a/tests/core/test_connections.py +++ b/tests/core/test_connections.py @@ -104,7 +104,7 @@ def validate_params(task, conn, params, nornir_config): assert getattr(task.host.connections[conn], k) == v -class Test(object): +class Test: @classmethod def setup_class(cls): ConnectionPluginRegister.deregister_all() @@ -200,7 +200,7 @@ def test_validate_params_overrides_groups(self, nornir): assert not r.failed -class TestConnectionPluginsRegistration(object): +class TestConnectionPluginsRegistration: def setup_method(self, method): ConnectionPluginRegister.deregister_all() ConnectionPluginRegister.register("dummy", DummyConnectionPlugin) diff --git a/tests/core/test_filter.py b/tests/core/test_filter.py index 276c56e4..74c27f93 100644 --- a/tests/core/test_filter.py +++ b/tests/core/test_filter.py @@ -3,7 +3,7 @@ from nornir.core.filter import AND, OR, F -class Test(object): +class Test: def test_simple(self, nornir): f = F(site="site1") filtered = sorted(list((nornir.inventory.filter(f).hosts.keys()))) diff --git a/tests/core/test_inventory.py b/tests/core/test_inventory.py index 995a865d..4f9563d1 100644 --- a/tests/core/test_inventory.py +++ b/tests/core/test_inventory.py @@ -16,7 +16,7 @@ inv_dict = {"hosts": hosts, "groups": groups, "defaults": defaults} -class Test(object): +class Test: def test_host(self): h = inventory.Host(name="host1", hostname="host1") assert h.hostname == "host1" diff --git a/tests/core/test_tasks.py b/tests/core/test_tasks.py index 3573a165..f78720a2 100644 --- a/tests/core/test_tasks.py +++ b/tests/core/test_tasks.py @@ -59,7 +59,7 @@ def fail_command_subtask_capture(task, fail_on=None): return "I captured this succcessfully" -class Test(object): +class Test: def test_task(self, nornir): result = nornir.run(a_task_for_testing) assert result diff --git a/tests/plugins/processors/test_serial.py b/tests/plugins/processors/test_serial.py index c21a9dae..47199d64 100644 --- a/tests/plugins/processors/test_serial.py +++ b/tests/plugins/processors/test_serial.py @@ -25,7 +25,7 @@ def failing_task_complex(task): a_task_for_testing(task, command="failme") -class TestSerialRunner(object): +class TestSerialRunner: def test_blocking_task_single_thread(self, nornir): t1 = datetime.datetime.now() nornir.with_runner(SerialRunner()).run(blocking_task, wait=0.5) diff --git a/tests/plugins/processors/test_threaded.py b/tests/plugins/processors/test_threaded.py index 2a0dfb08..b0974c6d 100644 --- a/tests/plugins/processors/test_threaded.py +++ b/tests/plugins/processors/test_threaded.py @@ -38,7 +38,7 @@ def verify_data_change(task): assert task.host["my_changed_var"] == task.host.name -class Test(object): +class Test: def test_blocking_task_multithreading(self, nornir): t1 = datetime.datetime.now() nornir.with_runner(ThreadedRunner(num_workers=NUM_WORKERS)).run(blocking_task, wait=2)