safe-typing is a module that provides a safe way to access types within the typing/typing_extensions namespaces.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file safe_typing-0.2.1.tar.gz.
File metadata
- Download URL: safe_typing-0.2.1.tar.gz
- Upload date:
- Size: 2.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88979d7c86cdc4f8ecac0a72c89ce3a246fd3ed52e826d573dc4a6ccc28bb647
|
|
| MD5 |
392d5ae82e58ab1cd762330041d83473
|
|
| BLAKE2b-256 |
de81ec49b2c7194b3cdea86a8334e2625b4238b704cde6420da8d04e69656b81
|
File details
Details for the file safe_typing-0.2.1-py3-none-any.whl.
File metadata
- Download URL: safe_typing-0.2.1-py3-none-any.whl
- Upload date:
- Size: 2.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6202c41c7771765514c5b05c106408c4f40890d65388b55b4b74918d3b4cb7db
|
|
| MD5 |
a1f72283e141125de919d386c6f96a7a
|
|
| BLAKE2b-256 |
f4495491f2cbfd0c80067fa14a74d9fc6f8f7b5bd19effd20980c9062905de42
|