https://github.com/fswair/safe-typing
safe-typing is a module that provides a safe way to access types within the typing namespace.
https://github.com/fswair/safe-typing
annotations pep8 python typing typing-extension
Last synced: about 2 months ago
JSON representation
safe-typing is a module that provides a safe way to access types within the typing namespace.
- Host: GitHub
- URL: https://github.com/fswair/safe-typing
- Owner: fswair
- License: mit
- Created: 2025-07-05T23:01:31.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2025-07-08T17:57:34.000Z (3 months ago)
- Last Synced: 2025-08-10T16:24:30.856Z (2 months ago)
- Topics: annotations, pep8, python, typing, typing-extension
- Language: Python
- Homepage: https://pypi.org/project/safe-typing/0.2.3/
- Size: 6.84 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://deepwiki.com/fswair/safe-typing)
Safe Typing is a module that provides a safe way to access types within the typing namespace.
It attempts to import types from the standard `typing` module first, and if not found,
it falls back to the `typing_extensions` module.
If a type is not found in either module, it returns a sentinel value `NotFound`.Stop writing this:
```python
import sysif sys.version_info >= (3, 8):
from typing import List, Dict, Tuple
else:
from typing_extensions import List, Dict, Tuple
```Use this instead:
```python
from typing import List as TypingList, Dict as TypingDict
from safe_typing import _no_raise, List, Dict, FooBar, NotFound# if you import _no_raise sentinel
# it will not raise an error when a name is not found in the module
# it will return a NotFound sentinel.
# otherwise, it will raise an ImportError
# if the name is not found in both typing and typing_extensions.assert List is TypingList # True
assert Dict is TypingDict # True
assert FooBar is NotFound # FooBar does not exist in either typing or typing_extensions```
You can reach me from contact@tomris.dev for collaborations, bug reports or feature requests.