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:
import sys
if sys.version_info >= (3, 8):
from typing import List, Dict, Tuple
else:
from typing_extensions import List, Dict, Tuple
Use this instead:
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.
Release files for safe-typing 0.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| safe_typing-0.2.3.tar.gz | 2.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| safe_typing-0.2.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 5.3 kB
Release files / safe_typing-0.2.3.tar.gz
| Download URL | safe_typing-0.2.3.tar.gz |
|---|---|
| Size | 2.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3900fcd4d6df3c002f790de80103b6c6e65219a81b29350401ffbd518cc7f9c7
|
|
BLAKE2b-256 checksum How to use checksums |
ef356bd2c76cd067befc9cbd70e621e2c1dcdababad36f98618ed403b17971e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.7
|
Release files / safe_typing-0.2.3-py3-none-any.whl
| Download URL | safe_typing-0.2.3-py3-none-any.whl |
|---|---|
| Size | 2.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2e418d81c35fc116c1c27e50ed2b20297d264f6a14f0679a64cc729072700742
|
|
BLAKE2b-256 checksum How to use checksums |
5054236f7f0ed95368a3ea9964d83aa9abfcf7dd21dc0cda23be97374684ada0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.7
|