Skip to content

Commit

Permalink
py.typed and strictly type-checked
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Aug 25, 2024
1 parent 07e9600 commit 9beaa7a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
Empty file added jaraco/compat/py.typed
Empty file.
21 changes: 14 additions & 7 deletions jaraco/compat/py38.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,40 @@
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),
)


r_fix = _fixer if sys.version_info < (3, 9) else lambda x: x

cache = (
functools.cache # type: ignore[attr-defined]
if sys.version_info >= (3, 9)
else functools.lru_cache(maxsize=None)
functools.cache if sys.version_info >= (3, 9) else functools.lru_cache(maxsize=None)
)
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 0 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,3 @@ type = [


[tool.setuptools_scm]


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

0 comments on commit 9beaa7a

Please sign in to comment.