Optional Object
Project description
Unavailable Object
A placeholder object for optional dependencies.
Usage
from unavailable_object import UnavailableObject
try:
import optional_module
except ImportError:
optional_module = UnavailableObject("optional_module")
Type Checking
To not disturb the type checker, the alternative definition of optional_object
should be guarded by if not TYPE_CHECKING
and type annotations put in quotes:
from typing import TYPE_CHECKING
from unavailable_object import UnavailableObject
try:
import optional_module
except ImportError:
if not TYPE_CHECKING:
optional_module = UnavailableObject("optional_module")
def foo(arg: "optional_module.SomeType") -> None:
pass
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
unavailable-object-0.0.1.tar.gz
(18.4 kB
view hashes)
Built Distribution
Close
Hashes for unavailable_object-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d037eaf6caa8cbeb022cb7bef163c0428fb732382e990a6abc8284646e4938a9 |
|
MD5 | f4db230ba654c5bb320b19f75b43ec74 |
|
BLAKE2b-256 | c6291a9af100676cffda8acd7aa0257d5512b06a8ee156a74d32ff2a0d2d806c |