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
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 details)
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