File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -125,12 +125,19 @@ Python or Cython type annotations should be included for all public APIs. Avoid
125125the use of ` Any ` unless absolutely necessary. The argument and return types as
126126defined in the docstrings should match the type annotations.
127127
128+ The use of ` if typing.TYPE_CHECK: ` blocks is often necessary to avoid import
129+ cycles. However, this can occasionally mask symbols used by Sphinx to make
130+ cross-references in the docs. If importing an object doesn't create a cycle, it
131+ should be imported outside of an ` if typing.TYPE_CHECK: ` block, even if it is
132+ only used in type annotations.
133+
128134### Semantics
129135
130- Designs involving manual resource management should be avoided. Where
131- appropriate, provide context managers (implemented with ` __enter__ ` and
132- ` __exit__ ` , not ` contextlib.contextmanager ` ) or RAII using a ` __del__ ` or
133- ` __dealloc__ ` method.
136+ APIs should exist for both manual resource management (such as ` close() ` ) and
137+ automatic resource management, using context managers or destructors where
138+ appropriate. Context managers should be implemented with ` __enter__ ` and
139+ ` __exit__ ` , not ` contextlib.contextmanager ` . For destructors use ` __dealloc__ `
140+ where possible, otherwise ` __del__ ` .
134141
135142### Documentation
136143
You can’t perform that action at this time.
0 commit comments