API Reference
SLOTHY_ENABLED: bool = not getenv('SLOTHY_DISABLE')
¶
Whether slothy is enabled.
lazy_importing(*, prevent_eager=True, stack_offset=1, _fallback=MISSING)
¶
Use slothy imports in a with statement.
Parameters:
-
prevent_eager(bool, default:True) –If True, will raise a
RuntimeErrorif slothy cannot guarantee to not fall back to eager imports on unsupported Python implementation. On supported Python implementations this parameter doesn't change the behavior. A general recommendation is to set this toTruein applications andFalsein libraries. -
stack_offset(int, default:1) –The stack offset to use.
Returns:
-
Iterator[None]–Context manager's underlying generator.
Source code in slothy/_importing.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
lazy_importing_if(condition, *, prevent_eager=True, stack_offset=1)
¶
Use slothy imports only if condition evaluates to truth.
Parameters:
-
condition(object) –The condition to evaluate.
-
prevent_eager(bool, default:True) –If True, will raise a
RuntimeErrorif slothy cannot guarantee to not fall back to eager imports on unsupported Python implementation. On supported Python implementations this parameter doesn't change the behavior. A general recommendation is to set this toTruein applications andFalsein libraries. -
stack_offset(int, default:1) –The stack offset to use.
Returns:
-
AbstractContextManager[None]–The context manager.
Source code in slothy/_importing.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
type_importing(*, default_type=Any, stack_offset=1)
¶
Use this to import symbols recognized by type checkers that do not exist at runtime.
This function should generally be considered a runtime-friendly alternative to
using if typing.TYPE_CHECKING.
Parameters:
-
default_type(object, default:Any) –The item to import in case of a failure. Defaults to
typing.Any -
stack_offset(int, default:1) –The stack offset to use.
Returns:
-
AbstractContextManager[None]–The context manager.
Source code in slothy/_importing.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |