Skip to content

Commit 6c44b68

Browse files
committed
Improve typing
1 parent 279cd43 commit 6c44b68

8 files changed

Lines changed: 21 additions & 9 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: v0.15.6
3+
rev: v0.15.7
44
hooks:
55
# Run the linter
66
- id: ruff-check

fido2/attestation/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from dataclasses import dataclass
3232
from enum import IntEnum, unique
3333
from functools import wraps
34-
from typing import Any, Mapping, Sequence
34+
from typing import Any, Mapping, Sequence, cast
3535

3636
from cryptography import x509
3737
from cryptography.exceptions import InvalidSignature as _InvalidSignature
@@ -197,7 +197,7 @@ def _validate_cert_common(cert):
197197

198198
def _default_attestations():
199199
return [
200-
cls() # type: ignore
200+
cast(type[Any], cls)()
201201
for cls in Attestation.__subclasses__()
202202
if getattr(cls, "FORMAT", "none") != "none"
203203
]

fido2/client/win_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ def __del__(self):
849849

850850

851851
HRESULT = ctypes.HRESULT # type: ignore
852-
WEBAUTHN = windll.webauthn # type: ignore
852+
WEBAUTHN = windll.webauthn
853853
WEBAUTHN_API_VERSION = WEBAUTHN.WebAuthNGetApiVersionNumber()
854854

855855
WEBAUTHN.WebAuthNIsUserVerifyingPlatformAuthenticatorAvailable.argtypes = [

fido2/ctap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import abc
3131
from enum import IntEnum, unique
3232
from threading import Event
33-
from typing import Callable, Iterator
33+
from typing import Callable, Iterator, cast
3434

3535

3636
@unique
@@ -177,5 +177,5 @@ def __init__(self, code: int):
177177
try:
178178
self.code = CtapError.ERR(code)
179179
except ValueError:
180-
self.code = CtapError.UNKNOWN_ERR(code) # type: ignore
180+
self.code = cast(CtapError.ERR, CtapError.UNKNOWN_ERR(code))
181181
super().__init__(f"CTAP error: {self.code}")

fido2/ctap2/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def args(*params) -> dict[int, Any]:
6262
class _CborDataObject(_DataClassMapping[int]):
6363
@classmethod
6464
def _get_field_key(cls, field: Field) -> int:
65-
return fields(cls).index(field) + 1 # type: ignore
65+
return fields(cls).index(field) + 1
6666

6767

6868
@dataclass(eq=False, frozen=True)

fido2/hid/openbsd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def get_descriptor(path):
102102
dev_info = UsbDeviceInfo()
103103

104104
try:
105-
fcntl.ioctl(f, USB_GET_DEVICEINFO, dev_info) # type: ignore
105+
fcntl.ioctl(f, USB_GET_DEVICEINFO, dev_info)
106106
finally:
107107
os.close(f)
108108

fido2/webauthn.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,9 @@ class _StringEnumMeta(EnumMeta):
345345
def _get_value(cls, value):
346346
return None
347347

348-
def __call__(cls, value, *args, **kwargs): # type: ignore
348+
def __call__( # pyright: ignore[reportIncompatibleMethodOverride]
349+
cls, value, *args, **kwargs
350+
):
349351
try:
350352
return super().__call__(value, *args, **kwargs)
351353
except ValueError:

pyproject.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,13 @@ venvPath = "."
6363
venv = ".venv"
6464
exclude = ["tests/", "docs/", "examples/"]
6565
reportPrivateImportUsage = false
66+
67+
[tool.ty.src]
68+
exclude = ["docs"]
69+
70+
[[tool.ty.overrides]]
71+
include = ["tests/**", "**/test_*.py"]
72+
73+
[tool.ty.overrides.rules]
74+
unresolved-attribute = "ignore"
75+
invalid-argument-type = "ignore"

0 commit comments

Comments
 (0)