From a60c01d488286c13ac1251a67f51b41b430b12dd Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Tue, 17 Sep 2024 15:33:14 +0200 Subject: [PATCH] topotato: new mypy, new warnings Updating mypy and/or pytest brought in a few more complaints. Signed-off-by: David Lamparter --- topotato/exceptions.py | 8 ++++++-- topotato/frr/core.py | 8 +++++--- topotato/frr/exceptions.py | 4 +++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/topotato/exceptions.py b/topotato/exceptions.py index 11ccd24..2fd12d9 100644 --- a/topotato/exceptions.py +++ b/topotato/exceptions.py @@ -69,11 +69,13 @@ def __init__(self, daemon: str, router: str, cmdline: Optional[str] = None): self.cmdline = cmdline super().__init__() - def __str__(self): + def __repr__(self) -> str: if self.cmdline: return f"{self.router}/{self.daemon}: {self.cmdline}" return f"{self.router}/{self.daemon}" + __str__ = __repr__ + @attr.s(eq=False, auto_attribs=True) class TopotatoRepr(TerminalRepr): excinfo: ExceptionInfo @@ -169,7 +171,7 @@ def __init__(self, failed_node, *args, **kwargs): super().__init__(*args, **kwargs) self.failed_node = failed_node - def __str__(self): + def __repr__(self) -> str: fno = self.failed_node parentnodeid = fno.parent.nodeid if fno.parent else "" sub_id = fno.nodeid.removeprefix(parentnodeid) @@ -179,6 +181,8 @@ def __str__(self): cause = "???" return f"{cause} in {sub_id}" + __str__ = __repr__ + # test coding errors diff --git a/topotato/frr/core.py b/topotato/frr/core.py index 1a745b1..8563162 100644 --- a/topotato/frr/core.py +++ b/topotato/frr/core.py @@ -187,12 +187,12 @@ def pytest_addoption(parser): def pytest_topotato_envcheck(cls, session: "ISession", result: EnvcheckResult): frrpath = get_dir(session, "--frr-builddir", "frr_builddir") - session.frr = cls(frrpath, result) + session.frr = cast(Self, cls(frrpath, result)) cls.setups[None] = session.frr for section in session.control.typed_sections.get(TargetFRRSection, []): _logger.debug("additional loading %r", section) - setup = cls(os.path.expanduser(section.builddir), result) + setup = cast(Self, cls(os.path.expanduser(section.builddir), result)) cls.setups[section.name] = setup def __init__(self, frrpath: str, result: EnvcheckResult): @@ -468,9 +468,11 @@ def __init__(self, router: str, daemon: str, errmsg: str): self.errmsg = errmsg super().__init__() - def __str__(self): + def __repr__(self) -> str: return f"{self.router}/{self.daemon}: {self.errmsg}" + __str__ = __repr__ + # pylint: disable=too-many-ancestors,too-many-instance-attributes class FRRRouterNS(TopotatoNetwork.RouterNS): diff --git a/topotato/frr/exceptions.py b/topotato/frr/exceptions.py index 2ffc711..02d1b96 100644 --- a/topotato/frr/exceptions.py +++ b/topotato/frr/exceptions.py @@ -41,9 +41,11 @@ def __init__( self.config = config super().__init__() - def __str__(self): + def __repr__(self) -> str: return f"{self.router}/startup-config-load" + __str__ = __repr__ + @attr.s(eq=False, auto_attribs=True) class TopotatoRepr(TerminalRepr): excinfo: ExceptionInfo