diff --git a/jaraco/compat/py.typed b/jaraco/compat/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/jaraco/compat/py38.py b/jaraco/compat/py38.py index dccf064..4c398ad 100644 --- a/jaraco/compat/py38.py +++ b/jaraco/compat/py38.py @@ -12,33 +12,46 @@ import functools import sys import types +from typing import Protocol, cast -def _fixer(orig: str): # pragma: no cover +class _RFixed(Protocol): + def removesuffix(self, suffix: str) -> str: ... + def removeprefix(self, prefix: str) -> str: ... + + +def _fixer(orig: str) -> _RFixed: # pragma: no cover """ Return an object that implements removesuffix and removeprefix on orig. """ - def removesuffix(suffix): + def removesuffix(suffix: str) -> str: # suffix='' should not call orig[:-0]. if suffix and orig.endswith(suffix): return orig[: -len(suffix)] else: return orig[:] - def removeprefix(prefix): + def removeprefix(prefix: str) -> str: if orig.startswith(prefix): return orig[len(prefix) :] else: return orig[:] - return types.SimpleNamespace(removesuffix=removesuffix, removeprefix=removeprefix) + return cast( + _RFixed, + types.SimpleNamespace(removesuffix=removesuffix, removeprefix=removeprefix), + ) + + +def passthrough(orig: str) -> str: + return orig -r_fix = _fixer if sys.version_info < (3, 9) else lambda x: x +r_fix = _fixer if sys.version_info < (3, 9) else passthrough cache = ( - functools.cache # type: ignore[attr-defined] + functools.cache # type: ignore[attr-defined, unused-ignore] if sys.version_info >= (3, 9) else functools.lru_cache(maxsize=None) ) diff --git a/mypy.ini b/mypy.ini index 83b0d15..8ff26e4 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,6 +1,6 @@ [mypy] # Is the project well-typed? -strict = False +strict = True # Early opt-in even when strict = False warn_unused_ignores = True diff --git a/pyproject.toml b/pyproject.toml index d304e5d..703ae21 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,7 +65,3 @@ type = [ [tool.setuptools_scm] - - -[tool.pytest-enabler.mypy] -# Disabled due to jaraco/skeleton#143