From e59211e63b121133708f7295f3a99a1704d6c09b Mon Sep 17 00:00:00 2001 From: Avasam Date: Mon, 26 Aug 2024 17:34:08 -0400 Subject: [PATCH] Re-enable mypy and add libraries to type checking --- keyring/backend.py | 1 + keyring/cli.py | 15 ++++++++++++--- keyring/compat/py312.py | 4 ++-- keyring/core.py | 2 +- mypy.ini | 4 ++-- pyproject.toml | 7 +++---- 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/keyring/backend.py b/keyring/backend.py index 647dff13..4f91e16e 100644 --- a/keyring/backend.py +++ b/keyring/backend.py @@ -114,6 +114,7 @@ def name(cls) -> str: """ parent, sep, mod_name = cls.__module__.rpartition('.') mod_name = mod_name.replace('_', ' ') + # mypy doesn't see `cls` is `type[Self]`, might be fixable in jaraco.classes return ' '.join([mod_name, cls.__name__]) # type: ignore[attr-defined] def __str__(self) -> str: diff --git a/keyring/cli.py b/keyring/cli.py index 30f945b2..8b3d712c 100644 --- a/keyring/cli.py +++ b/keyring/cli.py @@ -13,15 +13,24 @@ core, credentials, delete_password, + get_credential, get_password, set_keyring, set_password, - get_credential, ) from .util import platform_ class CommandLineTool: + # Attributes set dynamically by the ArgumentParser + keyring_path: str | None + keyring_backend: str | None + get_mode: str + output_format: str + operation: str + service: str + username: str + def __init__(self): self.parser = argparse.ArgumentParser() self.parser.add_argument( @@ -133,10 +142,10 @@ def _emit_plain(self, credential: credentials.Credential): print(credential.password) def _get_creds(self) -> credentials.Credential | None: - return get_credential(self.service, self.username) # type: ignore[attr-defined] + return get_credential(self.service, self.username) def _get_password(self) -> credentials.Credential | None: - password = get_password(self.service, self.username) # type: ignore[attr-defined] + password = get_password(self.service, self.username) return ( credentials.AnonymousCredential(password) if password is not None else None ) diff --git a/keyring/compat/py312.py b/keyring/compat/py312.py index 3493a417..f14044ae 100644 --- a/keyring/compat/py312.py +++ b/keyring/compat/py312.py @@ -3,7 +3,7 @@ __all__ = ['metadata'] -if sys.version_info > (3, 12): +if sys.version_info >= (3, 12): import importlib.metadata as metadata else: - import importlib_metadata as metadata # type: ignore[import-not-found, unused-ignore] + import importlib_metadata as metadata diff --git a/keyring/core.py b/keyring/core.py index 8232852e..ef18128e 100644 --- a/keyring/core.py +++ b/keyring/core.py @@ -106,7 +106,7 @@ def _detect_backend(limit: typing.Optional[LimitCallable] = None): or load_config() or max( # all keyrings passing the limit filter - filter(limit, backend.get_all_keyring()), # type: ignore[arg-type] # 659 + filter(limit, backend.get_all_keyring()), # type: ignore[arg-type] #659 default=fail.Keyring(), key=backend.by_priority, ) diff --git a/mypy.ini b/mypy.ini index 8bc6fbea..dcb61fc5 100644 --- a/mypy.ini +++ b/mypy.ini @@ -13,6 +13,6 @@ explicit_package_bases = True # Disable overload-overlap due to many false-positives disable_error_code = overload-overlap -# TODO: associate issues with these exclusions -[mypy-win32ctypes.*,win32cred.*,pywintypes,secretstorage.*,dbus.*,gi.*,shtab] +# TODO: Open upstream issues requesting typing +[mypy-win32ctypes.*,secretstorage.*,dbus.*] ignore_missing_imports = True diff --git a/pyproject.toml b/pyproject.toml index 2c798044..820e7a8e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -76,6 +76,9 @@ type = [ "pytest-mypy", # local + "pygobject-stubs", + "shtab", # Optional install for completion + "types-pywin32", ] completion = ["shtab >= 1.1.0"] @@ -96,7 +99,3 @@ keyring = "keyring.cli:main" [tool.setuptools_scm] - - -[tool.pytest-enabler.mypy] -# Disabled due to jaraco/skeleton#143