From b94449af1b4fbf467ad2c1a10046f589d2e52252 Mon Sep 17 00:00:00 2001 From: Marvin Vogt Date: Mon, 4 Dec 2023 16:53:35 +0000 Subject: [PATCH] Replace quoted types with `typing.Self` introduced in python3.11 --- src/anycastd/healthcheck/_cabourotte/result.py | 3 ++- src/anycastd/prefix/_frrouting/main.py | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/anycastd/healthcheck/_cabourotte/result.py b/src/anycastd/healthcheck/_cabourotte/result.py index 34f6a9d..703b26c 100644 --- a/src/anycastd/healthcheck/_cabourotte/result.py +++ b/src/anycastd/healthcheck/_cabourotte/result.py @@ -1,4 +1,5 @@ import datetime +from typing import Self import httpx from pydantic import BaseModel, Field @@ -16,7 +17,7 @@ class Result(BaseModel): source: str @classmethod - def from_json(cls, data: str | bytes | bytearray) -> "Result": + def from_json(cls, data: str | bytes | bytearray) -> Self: """Create a result from JSON returned by the cabourotte API.""" return cls.model_validate_json(data) diff --git a/src/anycastd/prefix/_frrouting/main.py b/src/anycastd/prefix/_frrouting/main.py index 440ec37..878168d 100644 --- a/src/anycastd/prefix/_frrouting/main.py +++ b/src/anycastd/prefix/_frrouting/main.py @@ -3,7 +3,7 @@ from contextlib import suppress from ipaddress import IPv4Network, IPv6Network from pathlib import Path -from typing import cast +from typing import Self, cast from anycastd._executor import Executor from anycastd.prefix._frrouting.exceptions import ( @@ -141,7 +141,7 @@ async def _run_vtysh_commands(self, commands: Sequence[str]) -> str: return stdout.decode("utf-8") - async def validate(self) -> "FRRoutingPrefix": + async def validate(self) -> Self: """Validate the prefix, raising an error on invalid configuration. Checks if the required VRF and BGP configuration exists. @@ -172,7 +172,7 @@ async def new( vrf: VRF = None, vtysh: Path = Path("/usr/bin/vtysh"), executor: Executor, - ) -> "FRRoutingPrefix": + ) -> Self: """Create a new validated FRRoutingPrefix. Creates a new FRRoutingPrefix instance while validating it against the @@ -182,7 +182,7 @@ async def new( A subclass of FRRConfigurationError if there is an issue with the FRRouting configuration. """ - return await FRRoutingPrefix( + return await cls( prefix=prefix, vrf=vrf, vtysh=vtysh, executor=executor ).validate()