Skip to content

Commit

Permalink
Remove Python 2 style class definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
ogenstad committed Jun 30, 2024
1 parent 320b229 commit b8cf402
Show file tree
Hide file tree
Showing 15 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion nornir/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions nornir/core/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def resolve(self, value: Optional[T]) -> T:
return v


class SSHConfig(object):
class SSHConfig:
__slots__ = ("config_file",)

class Parameters:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -190,7 +190,7 @@ def configure(self) -> None:
logger_.addHandler(stderr_handler)


class RunnerConfig(object):
class RunnerConfig:
__slots__ = ("options", "plugin")

class Parameters:
Expand All @@ -210,7 +210,7 @@ def dict(self) -> Dict[str, Any]:
}


class CoreConfig(object):
class CoreConfig:
__slots__ = "raise_on_error"

class Parameters:
Expand All @@ -225,7 +225,7 @@ def dict(self) -> Dict[str, Any]:
}


class Config(object):
class Config:
__slots__ = (
"core",
"inventory",
Expand Down
2 changes: 1 addition & 1 deletion nornir/core/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions nornir/core/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
HostOrGroup = TypeVar("HostOrGroup", "Host", "Group")


class BaseAttributes(object):
class BaseAttributes:
__slots__ = ("hostname", "password", "platform", "port", "username")

def __init__(
Expand Down Expand Up @@ -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__(
Expand Down
2 changes: 1 addition & 1 deletion nornir/core/state.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions nornir/core/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,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
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_InitNornir.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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() == {
Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())))
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/processors/test_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/processors/test_threaded.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b8cf402

Please sign in to comment.