diff --git a/pymapadmin/commands/base.py b/pymapadmin/commands/base.py index d0a07fb..4a1de91 100644 --- a/pymapadmin/commands/base.py +++ b/pymapadmin/commands/base.py @@ -7,7 +7,7 @@ from abc import abstractmethod, ABCMeta from argparse import ArgumentParser, Namespace from collections.abc import Mapping -from typing import Generic, Any, Final, Optional, TextIO +from typing import Generic, Any, Final, TextIO from grpclib.client import Channel @@ -85,7 +85,7 @@ def client(self) -> StubT: def _get_metadata(self) -> Mapping[str, str]: metadata = {'client-version': client_version} - token: Optional[str] = None + token: str | None = None if 'PYMAP_ADMIN_TOKEN' in os.environ: token = os.environ['PYMAP_ADMIN_TOKEN'] else: diff --git a/pymapadmin/commands/system.py b/pymapadmin/commands/system.py index 8d08879..695fa21 100644 --- a/pymapadmin/commands/system.py +++ b/pymapadmin/commands/system.py @@ -4,7 +4,7 @@ import getpass from argparse import ArgumentParser, FileType from contextlib import closing -from typing import Any, Optional, TextIO +from typing import Any, TextIO from .base import Command, AdminCommand from ..config import Config @@ -79,8 +79,8 @@ def method(self) -> MethodProtocol[LoginRequest, LoginResponse]: def build_request(self) -> LoginRequest: username: str = self.args.user - authzid: Optional[str] = self.args.authzid - expiration: Optional[float] = self.args.expiration + authzid: str | None = self.args.authzid + expiration: float | None = self.args.expiration if self.args.ask_password: password = getpass.getpass(f'{username} Password: ') elif self.args.password_file is not None: diff --git a/pymapadmin/commands/user.py b/pymapadmin/commands/user.py index 18fa65d..05d572c 100644 --- a/pymapadmin/commands/user.py +++ b/pymapadmin/commands/user.py @@ -4,7 +4,7 @@ import getpass from argparse import ArgumentParser, FileType from collections.abc import Mapping, Sequence -from typing import Any, Optional +from typing import Any from .base import AdminCommand from ..typing import AdminRequestT, AdminResponseT, MethodProtocol @@ -66,7 +66,7 @@ def add_subparser(cls, name: str, subparsers: Any) \ def method(self) -> MethodProtocol[SetUserRequest, UserResponse]: return self.client.SetUser - def getpass(self) -> Optional[str]: + def getpass(self) -> str | None: if self.args.no_password: return None elif self.args.password_file: diff --git a/pymapadmin/config.py b/pymapadmin/config.py index 16d371b..1381dfa 100644 --- a/pymapadmin/config.py +++ b/pymapadmin/config.py @@ -4,7 +4,6 @@ import os from argparse import Namespace from configparser import ConfigParser -from typing import Optional from .local import config_file, token_file, socket_file @@ -65,16 +64,16 @@ def build(cls, args: Namespace) -> ConfigParser: section['no_verify_cert'] = str(args.no_verify_cert) return parser - def _getstr(self, attr: str, envvar: str) -> Optional[str]: - val: Optional[str] = getattr(self._args, attr) + def _getstr(self, attr: str, envvar: str) -> str | None: + val: str | None = getattr(self._args, attr) if val is not None: return val if envvar in os.environ: return os.environ[envvar] return self._section.get(attr, fallback=None) - def _getint(self, attr: str, envvar: str) -> Optional[int]: - val: Optional[int] = getattr(self._args, attr) + def _getint(self, attr: str, envvar: str) -> int | None: + val: int | None = getattr(self._args, attr) if val is not None: return val if envvar in os.environ: @@ -91,31 +90,31 @@ def _getbool(self, attr: str, envvar: str) -> bool: return self._section.getboolean(attr, fallback=False) @property - def host(self) -> Optional[str]: + def host(self) -> str | None: return self._getstr('host', 'PYMAP_ADMIN_HOST') @property - def port(self) -> Optional[int]: + def port(self) -> int | None: return self._getint('port', 'PYMAP_ADMIN_PORT') @property - def token(self) -> Optional[str]: + def token(self) -> str | None: return self._getstr('token', 'PYMAP_ADMIN_TOKEN') @property - def cert(self) -> Optional[str]: + def cert(self) -> str | None: return self._getstr('cert', 'PYMAP_ADMIN_CERT') @property - def key(self) -> Optional[str]: + def key(self) -> str | None: return self._getstr('key', 'PYMAP_ADMIN_KEY') @property - def cafile(self) -> Optional[str]: + def cafile(self) -> str | None: return self._getstr('cafile', 'PYMAP_ADMIN_CAFILE') @property - def capath(self) -> Optional[str]: + def capath(self) -> str | None: return self._getstr('capath', 'PYMAP_ADMIN_CAPATH') @property diff --git a/pymapadmin/local.py b/pymapadmin/local.py index 31098ba..0f36876 100644 --- a/pymapadmin/local.py +++ b/pymapadmin/local.py @@ -6,7 +6,7 @@ from collections.abc import Sequence from functools import partial from pathlib import Path -from typing import Any, Union, Final, Optional +from typing import Any, Final from tempfile import gettempdir @@ -80,7 +80,7 @@ def _temp_path(self) -> Path: def _home_path(self) -> Path: return Path(self._config_home, 'pymap', self.filename) - def add(self, *custom: Union[None, str, Path]) -> None: + def add(self, *custom: None | str | Path) -> None: """Append the *custom* paths to :attr:`.custom`. Args: @@ -129,7 +129,7 @@ def get_all(self) -> Sequence[Path]: """Return all the paths that may contain the file.""" return list(self.custom) + [self._home_path, self._temp_path] - def find(self) -> Optional[Path]: + def find(self) -> Path | None: """Return the :class:`~pathlib.Path` of an existing file, if one exists. diff --git a/setup.cfg b/setup.cfg index 39b3329..f0327cc 100644 --- a/setup.cfg +++ b/setup.cfg @@ -5,6 +5,9 @@ ignore_missing_imports = True [flake8] exclude = pymapadmin/grpc +[tool:pytest] +asyncio_mode = auto + [coverage:report] omit = */main.py, */config.py, */local.py, */grpc/* exclude_lines = diff --git a/test/handler.py b/test/handler.py index 2ac3097..ebe8660 100644 --- a/test/handler.py +++ b/test/handler.py @@ -3,7 +3,7 @@ from abc import ABCMeta from collections.abc import Sequence -from typing import TypeVar, Generic, Optional +from typing import TypeVar, Generic from grpclib.server import Stream @@ -18,7 +18,7 @@ def __init__(self, req_type: type[RequestT], super().__init__() self.req_type = req_type self.responses = responses - self._request: Optional[RequestT] = None + self._request: RequestT | None = None @property def request(self) -> RequestT: diff --git a/test/test_health.py b/test/test_health.py index 6c7f145..5acecd7 100644 --- a/test/test_health.py +++ b/test/test_health.py @@ -2,7 +2,6 @@ from io import StringIO from argparse import Namespace -import pytest from grpclib.testing import ChannelFor from pymapadmin.commands.health import CheckCommand from grpclib.health.v1.health_grpc import HealthBase @@ -11,8 +10,6 @@ from handler import RequestT, ResponseT, MockHandler -pytestmark = pytest.mark.asyncio - class Handler(HealthBase, MockHandler[RequestT, ResponseT]): diff --git a/test/test_mailbox.py b/test/test_mailbox.py index 0445833..c89453a 100644 --- a/test/test_mailbox.py +++ b/test/test_mailbox.py @@ -2,7 +2,6 @@ from io import BytesIO, StringIO from argparse import Namespace -import pytest from grpclib.testing import ChannelFor from pymapadmin.commands.mailbox import AppendCommand from pymapadmin.grpc.admin_grpc import MailboxBase @@ -11,8 +10,6 @@ from handler import RequestT, ResponseT, MockHandler -pytestmark = pytest.mark.asyncio - class Handler(MailboxBase, MockHandler[RequestT, ResponseT]): diff --git a/test/test_system.py b/test/test_system.py index 5e7fac2..8e5e2b2 100644 --- a/test/test_system.py +++ b/test/test_system.py @@ -2,7 +2,6 @@ from io import StringIO from argparse import Namespace -import pytest from grpclib.testing import ChannelFor from pymapadmin.commands.system import LoginCommand, PingCommand from pymapadmin.grpc.admin_grpc import SystemBase @@ -11,8 +10,6 @@ from handler import RequestT, ResponseT, MockHandler -pytestmark = pytest.mark.asyncio - class Handler(SystemBase, MockHandler[RequestT, ResponseT]): diff --git a/test/test_user.py b/test/test_user.py index 7db97fe..8ca125b 100644 --- a/test/test_user.py +++ b/test/test_user.py @@ -13,8 +13,6 @@ from handler import RequestT, ResponseT, MockHandler -pytestmark = pytest.mark.asyncio - class Handler(UserBase, MockHandler[RequestT, ResponseT]):