Tighten typing
This commit is contained in:
parent
1651eaab84
commit
dde21d5dcd
@ -6,7 +6,6 @@ import platform
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
from .exceptions import InvalidHashError, UnsupportedParametersError
|
from .exceptions import InvalidHashError, UnsupportedParametersError
|
||||||
from .low_level import Type
|
from .low_level import Type
|
||||||
@ -15,7 +14,7 @@ from .low_level import Type
|
|||||||
NoneType = type(None)
|
NoneType = type(None)
|
||||||
|
|
||||||
|
|
||||||
def _check_types(**kw: Any) -> str | None:
|
def _check_types(**kw: tuple[object, type | tuple[type, ...]]) -> str | None:
|
||||||
"""
|
"""
|
||||||
Check each ``name: (value, types)`` in *kw*.
|
Check each ``name: (value, types)`` in *kw*.
|
||||||
|
|
||||||
@ -25,11 +24,11 @@ def _check_types(**kw: Any) -> str | None:
|
|||||||
for name, (value, types) in kw.items():
|
for name, (value, types) in kw.items():
|
||||||
if not isinstance(value, types):
|
if not isinstance(value, types):
|
||||||
if isinstance(types, tuple):
|
if isinstance(types, tuple):
|
||||||
types = ", or ".join(t.__name__ for t in types)
|
type_names = ", or ".join(t.__name__ for t in types)
|
||||||
else:
|
else:
|
||||||
types = types.__name__
|
type_names = types.__name__
|
||||||
errors.append(
|
errors.append(
|
||||||
f"'{name}' must be a {types} (got {type(value).__name__})"
|
f"'{name}' must be a {type_names} (got {type(value).__name__})"
|
||||||
)
|
)
|
||||||
|
|
||||||
if errors != []:
|
if errors != []:
|
||||||
|
|||||||
4
tox.ini
4
tox.ini
@ -95,13 +95,13 @@ commands = pyright src tests/typing
|
|||||||
description = Check API with ty
|
description = Check API with ty
|
||||||
deps = ty
|
deps = ty
|
||||||
dependency_groups = typing
|
dependency_groups = typing
|
||||||
commands = ty check tests/typing
|
commands = ty check src tests/typing
|
||||||
|
|
||||||
[testenv:typing-pyrefly]
|
[testenv:typing-pyrefly]
|
||||||
description = Check API with pyrefly
|
description = Check API with pyrefly
|
||||||
deps = pyrefly
|
deps = pyrefly
|
||||||
dependency_groups = typing
|
dependency_groups = typing
|
||||||
commands = pyrefly check tests/typing
|
commands = pyrefly check src tests/typing
|
||||||
|
|
||||||
|
|
||||||
[testenv:docs-{build,doctests,linkcheck}]
|
[testenv:docs-{build,doctests,linkcheck}]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user