strongtyping
raw JSON → 3.13.6 verified Mon Apr 27 auth: no python
A Python library providing decorators for runtime type checking of function parameters and return values, supporting TypedDict, Annotated, and custom validators. Current version 3.13.6, requires Python >=3.13. Release cadence is irregular, with frequent minor version bumps.
pip install strongtyping Common errors
error ImportError: cannot import name 'strong_typing' from 'strongtyping' ↓
cause Importing from the incorrect module path.
fix
Use: from strongtyping.strong_typing import strong_typing
error TypeError: unsupported operand type(s) for |: 'type' and 'type' ↓
cause Using PEP 604 union syntax (e.g., int | str) in Python <3.10, which strongtyping v3.13.2+ supports but requires Python 3.10+ for that syntax.
fix
Use Union[int, str] from typing instead, or upgrade Python to >=3.10.
error TypeMisMatch: Expected '<class 'int'>' but got '<class 'str'>' ↓
cause Standard runtime type mismatch error raised by the decorator.
fix
Correct the argument type to match the annotation.
Warnings
breaking Python 3.13 or higher is required. The library dropped support for earlier Python versions in v3.13.0. ↓
fix Upgrade Python to >=3.13 or use strongtyping <3.13.0 for older Python.
deprecated The old 'TypeMisMatch' class name (capital M) is deprecated in favor of 'TypeMismatch' (lowercase m) in recent versions. ↓
fix Use 'TypeMismatch' instead of 'TypeMisMatch' if available.
gotcha The decorators do not work with built-in typing generics like List[int] if the type is not imported from typing. Use the typing module types (e.g., typing.List) rather than built-in list subclassing. ↓
fix Import types from typing (e.g., from typing import List) and annotate with List[int].
Imports
- strong_typing wrong
from strongtyping import strong_typingcorrectfrom strongtyping.strong_typing import strong_typing - match_typing wrong
from strongtyping import match_typingcorrectfrom strongtyping.strong_typing import match_typing - TypeMisMatch
from strongtyping import TypeMisMatch
Quickstart
from strongtyping.strong_typing import strong_typing
@strong_typing
def greet(name: str) -> str:
return f"Hello {name}"
print(greet("World"))
# print(greet(42)) # raises TypeMisMatch