Skip to content

Commit

Permalink
Merge pull request #691 from Avasam/add-typed-libraries-to-type-checking
Browse files Browse the repository at this point in the history
Re-enable mypy and add libraries to type checking
  • Loading branch information
jaraco authored Sep 17, 2024
2 parents ae24cf0 + e59211e commit 98f027b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
1 change: 1 addition & 0 deletions keyring/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 12 additions & 3 deletions keyring/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions keyring/compat/py312.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion keyring/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
4 changes: 2 additions & 2 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ disable_error_code =
# Disable due to many false positives
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
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ type = [
"pytest-mypy",

# local
"pygobject-stubs",
"shtab", # Optional install for completion
"types-pywin32",
]

completion = ["shtab >= 1.1.0"]
Expand All @@ -96,7 +99,3 @@ keyring = "keyring.cli:main"


[tool.setuptools_scm]


[tool.pytest-enabler.mypy]
# Disabled due to jaraco/skeleton#143

0 comments on commit 98f027b

Please sign in to comment.