From 364385310823e02c590fdb58ffc45dfb316e1e77 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone <exarkun@twistedmatrix.com> Date: Wed, 9 Feb 2022 18:27:20 -0500 Subject: [PATCH] try to apply mypy and fix what type errors I may --- pyproject.toml | 4 ++++ shell.nix | 2 ++ src/_zkapauthorizer/config.py | 5 ++--- src/_zkapauthorizer/lease_maintenance.py | 4 ++-- src/_zkapauthorizer/tests/test_plugin.py | 6 ++---- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 0a7432c..4e6738f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,3 +43,7 @@ extend-exclude = ''' [tool.isort] profile = "black" skip = ["src/_zkapauthorizer/_version.py"] + +[tool.mypy] +namespace_packages = true +plugins = "mypy_zope:plugin" diff --git a/shell.nix b/shell.nix index c7ed137..e80e642 100644 --- a/shell.nix +++ b/shell.nix @@ -17,6 +17,8 @@ let ]; requirements = '' + mypy + mypy-zope ${builtins.readFile ./requirements/test.in} ${zkapauthorizer.requirements} ''; diff --git a/src/_zkapauthorizer/config.py b/src/_zkapauthorizer/config.py index a3ab588..17e9c87 100644 --- a/src/_zkapauthorizer/config.py +++ b/src/_zkapauthorizer/config.py @@ -17,7 +17,7 @@ Helpers for reading values from the Tahoe-LAFS configuration. """ from datetime import timedelta -from typing import Optional +from typing import Any, Optional from allmydata.node import _Config @@ -113,7 +113,7 @@ def get_configured_lease_duration(node_config): return int(upper_bound - min_time_remaining) -def _read_duration(cfg, option, default): +def _read_duration(cfg: _Config, option: str, default: Any) -> Optional[timedelta]: """ Read an integer number of seconds from the ZKAPAuthorizer section of a Tahoe-LAFS config. @@ -124,7 +124,6 @@ def _read_duration(cfg, option, default): :return: ``None`` if the option is missing, otherwise the parsed duration as a ``timedelta``. """ - # type: (_Config, str) -> Optional[timedelta] section_name = "storageclient.plugins." + NAME value_str = cfg.get_config( section=section_name, diff --git a/src/_zkapauthorizer/lease_maintenance.py b/src/_zkapauthorizer/lease_maintenance.py index 10846fe..a7cc77c 100644 --- a/src/_zkapauthorizer/lease_maintenance.py +++ b/src/_zkapauthorizer/lease_maintenance.py @@ -20,7 +20,7 @@ refresh leases on all shares reachable from a root. from datetime import datetime, timedelta from errno import ENOENT from functools import partial -from typing import Any, Dict, Iterable +from typing import Any, Callable, Dict, Iterable import attr from allmydata.interfaces import IDirectoryNode, IFilesystemNode @@ -321,7 +321,7 @@ class _FuzzyTimerService(Service): operation = attr.ib() initial_interval = attr.ib() sample_interval_distribution = attr.ib() - get_config = attr.ib() # type: () -> Any + get_config: Callable[[], Any] = attr.ib() reactor = attr.ib() def startService(self): diff --git a/src/_zkapauthorizer/tests/test_plugin.py b/src/_zkapauthorizer/tests/test_plugin.py index 1c50a99..98147f8 100644 --- a/src/_zkapauthorizer/tests/test_plugin.py +++ b/src/_zkapauthorizer/tests/test_plugin.py @@ -745,24 +745,22 @@ class LeaseMaintenanceServiceTests(TestCase): ) -def has_lease_maintenance_service(): +def has_lease_maintenance_service() -> Matcher: """ Return a matcher for a Tahoe-LAFS client object that has a lease maintenance service. """ - # type: () -> Matcher return AfterPreprocessing( lambda client: client.getServiceNamed(SERVICE_NAME), Always(), ) -def has_lease_maintenance_configuration(lease_maint_config): +def has_lease_maintenance_configuration(lease_maint_config: LeaseMaintenanceConfig) -> Matcher: """ Return a matcher for a Tahoe-LAFS client object that has a lease maintenance service with the given configuration. """ - # type: (LeaseMaintenanceConfig) -> Matcher def get_lease_maintenance_config(lease_maint_service): return lease_maint_service.get_config() -- GitLab