Skip to content

Commit 43d6a63

Browse files
authored
Add information that pyi files are used in runtime when use attach_stub (#47)
1 parent acbce79 commit 43d6a63

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,15 @@ Except that all subpackages (such as `rank`) and functions (such as `sobel`) are
7777
Static type checkers and IDEs cannot infer type information from
7878
lazily loaded imports. As a workaround you can load [type
7979
stubs](https://mypy.readthedocs.io/en/stable/stubs.html) (`.pyi`
80-
files) with `lazy.attach_stub`.
80+
files) with `lazy.attach_stub`:
81+
82+
```python
83+
import lazy_loader as lazy
84+
__getattr__, __dir__, _ = lazy.attach_stub(__name__, "subpackages.pyi")
85+
```
86+
87+
Note that, since imports are now defined in `.pyi` files, those
88+
are not only necessary for type checking but also at runtime.
8189

8290
The SPEC [describes this workaround in more
8391
detail](https://scientific-python.org/specs/spec-0001/#type-checkers).

0 commit comments

Comments
 (0)