Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

safe_typing-0.2.3.tar.gz (2.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

safe_typing-0.2.3-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

Details for the file safe_typing-0.2.3.tar.gz.

File metadata

  • Download URL: safe_typing-0.2.3.tar.gz
  • Upload date:
  • Size: 2.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for safe_typing-0.2.3.tar.gz
Algorithm Hash digest
SHA256 3900fcd4d6df3c002f790de80103b6c6e65219a81b29350401ffbd518cc7f9c7
MD5 e04f26cd0ff48022dd1ed8ddc2fda031
BLAKE2b-256 ef356bd2c76cd067befc9cbd70e621e2c1dcdababad36f98618ed403b17971e0

See more details on using hashes here.

File details

Details for the file safe_typing-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: safe_typing-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 2.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for safe_typing-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2e418d81c35fc116c1c27e50ed2b20297d264f6a14f0679a64cc729072700742
MD5 d255a77f4899edc40e3158dff81dce7e
BLAKE2b-256 5054236f7f0ed95368a3ea9964d83aa9abfcf7dd21dc0cda23be97374684ada0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page