Verified Commit 0f1145c8 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Modernise typing styles

parent c079c41f
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -26,15 +26,13 @@ from contextlib import suppress
from os import PathLike
from typing import Awaitable
from typing import Callable
from typing import Dict
from typing import Protocol
from typing import Union

import sniffio

ConnectorFn = Callable[[str, str], Awaitable['DatagramSocket']]

connectors: Dict[str, ConnectorFn] = {}
connectors: dict[str, ConnectorFn] = {}


class DatagramSocket(Protocol):
@@ -57,7 +55,7 @@ class ConnectedUNIXMixin:
		os.unlink(path)


async def connect_unix_datagram(path: Union[str, PathLike[str]]) -> DatagramSocket:
async def connect_unix_datagram(path: str | PathLike[str]) -> DatagramSocket:
	"""
	Return an AnyIO socket connected to a Unix datagram socket

+2 −3
Original line number Diff line number Diff line
#  Copyright 2019-2021  Dom Sekotill <dom.sekotill@kodo.org.uk>
#  Copyright 2019-2021, 2024  Dom Sekotill <dom.sekotill@kodo.org.uk>
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@ from __future__ import annotations

import pathlib
from os import PathLike
from typing import Set

from . import consts
from .base import BaseClient
@@ -40,7 +39,7 @@ class GlobalClient(BaseClient):
		await super().connect(path)
		self.ctrl_dir = path.parent

	async def list_interfaces(self) -> Set[str]:
	async def list_interfaces(self) -> set[str]:
		"""
		Return a set of the interfaces currently managed by the daemon
		"""
+11 −14
Original line number Diff line number Diff line
@@ -25,12 +25,9 @@ from re import compile as regex
from types import TracebackType as Traceback
from typing import AsyncContextManager
from typing import Callable
from typing import Dict
from typing import Optional
from typing import Tuple
from typing import Type
from typing import TypeVar
from typing import Union
from typing import overload

import anyio
@@ -52,7 +49,7 @@ class EventPriority(enum.IntEnum):
	Event Message priorities
	"""

	def get_logger_level(self, *, _mapping: Dict[EventPriority, int] = {}) -> int:
	def get_logger_level(self, *, _mapping: dict[EventPriority, int] = {}) -> int:
		"""
		Return a logging level matching the `wpa_supplicant` priority level
		"""
@@ -92,15 +89,15 @@ class BaseClient:

	event_regex = regex(r"<([0-9]+)>(?:((?:CTRL|WPS|AP|P2P)-[A-Z0-9-]+)(?:\s|$))?(.+)?")

	def __init__(self, *, logger: Optional[logging.Logger] = None):
	def __init__(self, *, logger: logging.Logger | None = None) -> None:
		self.logger = logger or logging.getLogger(__package__)
		self.ctrl_dir = None
		self.sock: Optional[DatagramSocket] = None
		self.sock: DatagramSocket | None = None
		self._lock = anyio.Lock()
		self._condition = anyio.Condition()
		self._handler_active = False
		self._reply: Union[_ReplyState, str] = _ReplyState.NOTHING
		self._event: Optional[EventInfo]
		self._reply: _ReplyState | str = _ReplyState.NOTHING
		self._event: EventInfo | None
		self._eventcount = 0

	async def __aenter__(self) -> BaseClient:
@@ -108,9 +105,9 @@ class BaseClient:

	async def __aexit__(
		self,
		_et: Optional[Type[BaseException]],
		_e: Optional[BaseException],
		_tb: Optional[Traceback],
		_et: type[BaseException] | None,
		_e: BaseException | None,
		_tb: Traceback | None,
	) -> None:
		await self.disconnect()

@@ -158,8 +155,8 @@ class BaseClient:
		*args: str,
		separator: str = consts.SEPARATOR_TAB,
		expect: str = consts.RESPONSE_OK,
		convert: Optional[Callable[[str], T]] = None,
	) -> Optional[T]:
		convert: Callable[[str], T] | None = None,
	) -> T | None:
		"""
		Send a message and await a response

@@ -284,7 +281,7 @@ class BaseClient:
		self._event = (prio, name, msg or None)

	class _AttachContext:
		def __init__(self, client: BaseClient):
		def __init__(self, client: BaseClient) -> None:
			self.client = client

		async def __aenter__(self) -> None:
+1 −1
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ class InterfaceClient(BaseClient):
					return
				yield bss

	async def add_network(self, configuration: Dict[str, object]) -> int:
	async def add_network(self, configuration: dict[str, object]) -> int:
		"""Add a new network configuration"""
		netid = await self.send_command(consts.COMMAND_ADD_NETWORK, convert=str)
		for var, val in configuration.items():