diff --git a/pyproject.toml b/pyproject.toml index 63365ae1..a0e98ead 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -137,16 +137,13 @@ reportUnsupportedDunderAll = "error" [tool.mypy] python_version = "3.9" # Target oldest supported Python version strict = true +check_untyped_defs = true # Strict check on all defs show_column_numbers = true warn_unused_ignores = false # Change from pandas # Partial stubs are acceptable disallow_any_generics = false disallow_incomplete_defs = false disallow_untyped_defs = false -# Allow dynamic typing in our own code -warn_return_any = false # TODO -disallow_untyped_calls = false # TODO -check_untyped_defs = true # Suppressing errors disable_error_code = [ # Not all imports in these stubs are gonna be typed diff --git a/stubs/matplotlib/colors.pyi b/stubs/matplotlib/colors.pyi index a1e38290..f0c7e853 100644 --- a/stubs/matplotlib/colors.pyi +++ b/stubs/matplotlib/colors.pyi @@ -128,24 +128,42 @@ class CenteredNorm(Normalize): def __call__(self, value, clip: bool = ...): ... def make_norm_from_scale(scale_cls, base_norm_cls=..., *, init=...): ... -@make_norm_from_scale(FuncScale, init=lambda functions, vmin=None, vmax=None, clip=False: None) -class FuncNorm(Normalize): ... -@make_norm_from_scale(functools.partial(LogScale, nonpositive="mask")) +class FuncNorm(Normalize): + def __init__( + self, + functions: tuple[Callable, Callable], + vmin: float | None = ..., + vmax: float | None = ..., + clip: bool = ..., + ) -> None: ... + class LogNorm(Normalize): ... -@make_norm_from_scale( - SymmetricalLogScale, - init=lambda linthresh, linscale=1, vmin=None, vmax=None, clip=False, *, base=10: None, -) class SymLogNorm(Normalize): + def __init__( + self, + linthresh: float, + linscale: float = ..., + vmin: float | None = ..., + vmax: float | None = ..., + clip: bool = ..., + *, + base: float = ..., + ) -> None: ... @property def linthresh(self): ... @linthresh.setter def linthresh(self, value): ... -@make_norm_from_scale(AsinhScale, init=lambda linear_width=1, vmin=None, vmax=None, clip=False: None) class AsinhNorm(Normalize): + def __init__( + self, + linear_width: float = ..., + vmin: float | None = ..., + vmax: float | None = ..., + clip: bool = ..., + ) -> None: ... @property def linear_width(self): ... @linear_width.setter diff --git a/stubs/matplotlib/transforms.pyi b/stubs/matplotlib/transforms.pyi index 37276d46..e3319605 100644 --- a/stubs/matplotlib/transforms.pyi +++ b/stubs/matplotlib/transforms.pyi @@ -199,7 +199,7 @@ class Transform(TransformNode): output_dims = ... is_separable = ... has_inverse = ... - def __init_subclass__(cls): ... + def __init_subclass__(cls) -> None: ... def __add__(self, other: Transform) -> Transform: ... @property def depth(self) -> int: ... diff --git a/stubs/sympy-stubs/assumptions/assume.pyi b/stubs/sympy-stubs/assumptions/assume.pyi index c8145b76..b2daa957 100644 --- a/stubs/sympy-stubs/assumptions/assume.pyi +++ b/stubs/sympy-stubs/assumptions/assume.pyi @@ -35,9 +35,9 @@ class Predicate(Boolean, metaclass=PredicateMeta): @property def name(self) -> str: ... @classmethod - def register(cls, *types, **kwargs): ... + def register(cls, *types: type, **kwargs: object) -> Callable[..., None]: ... @classmethod - def register_many(cls, *types, **kwargs) -> Callable[..., None]: ... + def register_many(cls, *types: type, **kwargs: object) -> Callable[..., None]: ... def __call__(self, *args) -> AppliedPredicate: ... def eval(self, args, assumptions=...) -> None: ... diff --git a/tests/run_hygiene.py b/tests/run_hygiene.py index 97770ee6..a7563b4a 100644 --- a/tests/run_hygiene.py +++ b/tests/run_hygiene.py @@ -4,23 +4,23 @@ from pathlib import Path -def install_requirements(): +def install_requirements() -> None: print("\nInstalling requirements...") subprocess.check_call((sys.executable, "-m", "pip", "install", "pip>=25.1")) subprocess.check_call((sys.executable, "-m", "pip", "install", "--upgrade", "--group", "hygiene")) -def run_ruff_fix(): +def run_ruff_fix() -> subprocess.CompletedProcess[bytes]: print("\nRunning Ruff check --fix...") return subprocess.run((sys.executable, "-m", "ruff", "check", "--fix")) -def run_ruff_format(): +def run_ruff_format() -> subprocess.CompletedProcess[bytes]: print("\nRunning Ruff format...") return subprocess.run((sys.executable, "-m", "ruff", "format")) -def main(): +def main() -> None: os.chdir(Path(__file__).parent.parent) install_requirements() diff --git a/tests/run_tests.py b/tests/run_tests.py index 5fcd5a8b..bd0e6529 100644 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -4,13 +4,13 @@ from pathlib import Path -def install_requirements(): +def install_requirements() -> None: print("\nInstalling requirements...") subprocess.check_call((sys.executable, "-m", "pip", "install", "pip>=25.1")) subprocess.check_call((sys.executable, "-m", "pip", "install", "--upgrade", "--group", "tests")) -def run_pyright(): +def run_pyright() -> subprocess.CompletedProcess[bytes]: print("\nRunning Pyright...") # https://github.com/RobertCraigie/pyright-python#keeping-pyright-and-pylance-in-sync os.environ.pop("PYRIGHT_PYTHON_FORCE_VERSION", None) @@ -18,12 +18,12 @@ def run_pyright(): return subprocess.run((sys.executable, "-m", "pyright")) -def run_mypy(): +def run_mypy() -> subprocess.CompletedProcess[bytes]: print("\nRunning mypy...") return subprocess.run((sys.executable, "-m", "mypy", ".")) -def main(): +def main() -> None: os.chdir(Path(__file__).parent.parent) install_requirements() diff --git a/utils/count_ids.py b/utils/count_ids.py index ef0a89ec..f713db40 100644 --- a/utils/count_ids.py +++ b/utils/count_ids.py @@ -1,4 +1,5 @@ #!/bin/python +from __future__ import annotations __doc__ = """Count IDs. @@ -23,7 +24,7 @@ import docopt -def count(root, suffix, regex, uniq): +def count(root: str | None, suffix: str | None, regex: str | re.Pattern[str] | None, uniq: bool) -> None: if root is None: root = "." filepat = "*" if suffix is None else "*." + suffix[suffix.find(".") + 1 :] diff --git a/utils/validate_stubs.py b/utils/validate_stubs.py index 278ef6bc..b754b86c 100644 --- a/utils/validate_stubs.py +++ b/utils/validate_stubs.py @@ -66,7 +66,7 @@ def import_dual(m: str, stub_path: str) -> tuple: """ - def _clean(m): + def _clean(m: str) -> None: to_del = [k for k in sys.modules.keys() if k == m or k.startswith(m + ".")] for k in to_del: del sys.modules[k] @@ -99,7 +99,7 @@ class ItemType(Enum): def __init__( self, file: str, module: str, name: str, object_: object, type_: ItemType, children: dict[str, Item] | None = None - ): + ) -> None: self.file = file self.module = module self.name = name @@ -109,25 +109,25 @@ def __init__( self.done = False self.analog: Item | None = None - def ismodule(self): + def ismodule(self) -> bool: return self.type_ == Item.ItemType.MODULE - def isclass(self): + def isclass(self) -> bool: return self.type_ == Item.ItemType.CLASS - def isfunction(self): + def isfunction(self) -> bool: return self.type_ == Item.ItemType.FUNCTION @staticmethod - def make_function(file: str, module: str, name: str, object_: object): + def make_function(file: str, module: str, name: str, object_: object) -> Item: return Item(file, module, name, object_, Item.ItemType.FUNCTION) @staticmethod - def make_class(file: str, module: str, name: str, object_: object, children: dict[str, Item]): + def make_class(file: str, module: str, name: str, object_: object, children: dict[str, Item]) -> Item: return Item(file, module, name, object_, Item.ItemType.CLASS, children) @staticmethod - def make_module(file: str, module: str, name: str, object_: object, children: dict[str, Item]): + def make_module(file: str, module: str, name: str, object_: object, children: dict[str, Item]) -> Item: return Item(file, module, name, object_, Item.ItemType.MODULE, children) @@ -144,7 +144,9 @@ def isfrompackage(v: object, path: str) -> bool: def isfrommodule(v: object, module: str, default: bool = True) -> bool: try: # Make sure it came from this module - return v.__dict__["__module__"] == module + __module__ = v.__dict__["__module__"] + assert isinstance(__module__, str) + return module == __module__ except Exception: return default