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.1.tar.gz (2.3 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.1-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

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

Hashes for safe_typing-0.2.1.tar.gz
Algorithm Hash digest
SHA256 88979d7c86cdc4f8ecac0a72c89ce3a246fd3ed52e826d573dc4a6ccc28bb647
MD5 392d5ae82e58ab1cd762330041d83473
BLAKE2b-256 de81ec49b2c7194b3cdea86a8334e2625b4238b704cde6420da8d04e69656b81

See more details on using hashes here.

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

Hashes for safe_typing-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6202c41c7771765514c5b05c106408c4f40890d65388b55b4b74918d3b4cb7db
MD5 a1f72283e141125de919d386c6f96a7a
BLAKE2b-256 f4495491f2cbfd0c80067fa14a74d9fc6f8f7b5bd19effd20980c9062905de42

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