Registry / type-stubs / typish

typish

JSON →
library1.9.3pypypi✓ verified 22d ago

Typish is a Python library that extends Python's native `typing` module, offering advanced functionality for thorough type checks, instance checks considering generics, and typesafe duck-typing. It provides utilities for introspection of type hints, such as retrieving origins and arguments of generic types, and determining optionality. Currently at version 1.9.3, it maintains a regular release cadence with a focus on bug fixes and compatibility improvements across Python versions.

pip install typish
INSTALL
IMPORT
SIG · TYPISH
T
typish
type-stubspythonv1.9.3
Install
1.5s avg
Import
41ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.9.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.042s · 18.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.040s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

instance_of
from typish import instance_of
Used for advanced instance checks that respect generics and duck-typing.
get_origin
from typish import get_origin
Retrieves the non-generic base type of a generic type (e.g., `list` from `List[str]`).
is_optional_type
from typish import is_optional_type
Checks if a given type is considered optional (e.g., `Optional[str]` or `str | None`).
ClsDict
from typish import ClsDict
A dictionary that uses instance checking for keys, useful for dispatching based on type.
hintable
from typish import hintable
Decorator to capture the type hint of a variable before a function call.
Literal
from typish import Literal
A backwards-compatible variant of `typing.Literal` for older Python versions.

This quickstart demonstrates `typish.instance_of` for type-safe checks with generics, `typish.get_origin` for inspecting generic types, and `typish.is_optional_type` for identifying optional type hints. It also shows `typish.Literal` for broad compatibility of literal types.

from typing import Iterable from typish import instance_of # Basic instance check with generics result_iterable = instance_of([1, 2, 3], Iterable[int]) print(f"Is [1, 2, 3] an Iterable[int]? {result_iterable}") from typish import get_origin from typing import List, Dict # Get the origin of a generic type origin_list = get_origin(List[str]) origin_dict = get_origin(Dict[str, int]) print(f"Origin of List[str]: {origin_list}") print(f"Origin of Dict[str, int]: {origin_dict}") from typish import is_optional_type, Literal from typing import Optional, Union # Check for optional types is_opt_str = is_optional_type(Optional[str]) is_union_none = is_optional_type(Union[int, None]) print(f"Is Optional[str] optional? {is_opt_str}") print(f"Is Union[int, None] optional? {is_union_none}") # Using typish.Literal for older Python compatibility (if needed) from typish import Literal def process_status(status: Literal['success', 'failure']): return f"Processing status: {status}" print(process_status('success'))
Debug
Known issues
gotchaPrior to v1.9.2, `get_origin` did not correctly handle parameterized collections (e.g., `dict[str, str]`) in Python 3.9+.
fix
Upgrade to `typish` version 1.9.2 or newer to ensure correct behavior with modern Python type hints. Alternatively, avoid using `get_origin` with directly parameterized built-in collections on affected Python versions.
affects: <1.9.2
gotchaIn versions older than 1.8.0, `instance_of` could fail when used with `Literal` types containing multiple arguments.
fix
Upgrade to `typish` version 1.8.0 or newer for robust `instance_of` checks with `Literal`.
affects: <1.8.0
gotchaBefore v1.8.0, `get_origin` might have failed when dealing with classes that had shadowing names, leading to incorrect type introspection.
fix
Update to `typish` version 1.8.0 or later to resolve issues with `get_origin` and shadowed class names.
affects: <1.8.0
gotchaPython's native `typing` module has evolved significantly across versions (e.g., `Union[X, Y]` vs `X | Y` syntax). While `typish` aims to provide compatibility, mixing `typing` constructs from different Python versions or relying on `typish` to completely abstract away core `typing` changes might lead to subtle issues if not carefully managed.
fix
Be mindful of your target Python versions when using complex type hints. When backporting or ensuring broad compatibility, use `from typish import Literal` and similar constructs, as `typish` often provides backward-compatible wrappers for newer `typing` features. Refer to Python's `typing` module documentation for version-specific syntax.
affects: All versions
Upgrade
Version history
1.9.3latest on PyPI · released Aug 5, 2021
Audit
Dependencies
pythonrequiredRequired for execution, supports Python 3.5, 3.6, 3.7, 3.8, 3.9 as per PyPI metadata. Later versions (3.9+) have specific bug fixes and compatibility improvements.
nptypingoptionalCompatibility with nptyping was added in v1.8.0, indicating it works well with this library for NumPy type hints.
Agent activity
44 hits · last 30 days
node
38
OpenAI (training)
1
Resources
typish — pip install typish · libregistry