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.2.tar.gz
(18.8 kB
view hashes)
Built Distribution
Close
Hashes for unavailable_object-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87f466ea3cff25080e2ecbe562e70596a5fb8e73ca499c512c0b7c4b38d8ef1e |
|
MD5 | 77a65bd28a7b06bc293b5fe0548df4df |
|
BLAKE2b-256 | 0c62e9152b7963c11c19bb0ed917b4ba4c0e031176ba99a025b13d60aea9b37d |