From 5e828139c508cf92d90267c92a0049a46d3416c1 Mon Sep 17 00:00:00 2001 From: Grzegorz Bokota Date: Mon, 13 Mar 2023 19:05:09 +0000 Subject: [PATCH 1/3] Add information that pyi files are used in runtime when use attach_stub --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 24ae77b..59dbe69 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,15 @@ lazily loaded imports. As a workaround you can load [type stubs](https://mypy.readthedocs.io/en/stable/stubs.html) (`.pyi` files) with `lazy.attach_stub`. +```python +import lazy_loader as lazy +__getattr__, __dir__, _ = lazy.attach_stub(__name__, "subpackages.pyi") +``` + +In such scenario the `lazy_loader` determine imports base on `.pyi`, +so `.pyi` files are then required not only for type checking but also in runtime. +(during freezing app that uses library using `lazy_loader` it is required to collect also `.pyi` files) + The SPEC [describes this workaround in more detail](https://scientific-python.org/specs/spec-0001/#type-checkers). From 563064d8870c3a036f95e7d018864fab7e4e17fe Mon Sep 17 00:00:00 2001 From: Grzegorz Bokota Date: Mon, 13 Mar 2023 20:16:22 +0100 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Stefan van der Walt --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 59dbe69..d5e4b1f 100644 --- a/README.md +++ b/README.md @@ -77,16 +77,15 @@ Except that all subpackages (such as `rank`) and functions (such as `sobel`) are Static type checkers and IDEs cannot infer type information from lazily loaded imports. As a workaround you can load [type stubs](https://mypy.readthedocs.io/en/stable/stubs.html) (`.pyi` -files) with `lazy.attach_stub`. +files) with `lazy.attach_stub`: ```python import lazy_loader as lazy __getattr__, __dir__, _ = lazy.attach_stub(__name__, "subpackages.pyi") ``` -In such scenario the `lazy_loader` determine imports base on `.pyi`, -so `.pyi` files are then required not only for type checking but also in runtime. -(during freezing app that uses library using `lazy_loader` it is required to collect also `.pyi` files) +Note that, since imports are now defined in `.pyi` files, those +are not only necessary for type checking but also at runtime. The SPEC [describes this workaround in more detail](https://scientific-python.org/specs/spec-0001/#type-checkers). From f178c63e042f4890630d62979e7f71d3631919bd Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Mon, 13 Mar 2023 12:19:10 -0700 Subject: [PATCH 3/3] Lint --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d5e4b1f..ade8b34 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ lazily loaded imports. As a workaround you can load [type stubs](https://mypy.readthedocs.io/en/stable/stubs.html) (`.pyi` files) with `lazy.attach_stub`: -```python +```python import lazy_loader as lazy __getattr__, __dir__, _ = lazy.attach_stub(__name__, "subpackages.pyi") ```