@@ -147,18 +147,18 @@ The Python-specific directives are:
147147[ ` # gazelle:python_generate_pyi_deps bool ` ] ( #directive-python-generate-pyi-deps )
148148: Controls whether to generate a separate ` pyi_deps ` attribute for
149149 type-checking dependencies or merge them into the regular ` deps `
150- attribute. When ` false ` (default), type-checking dependencies are
151- merged into ` deps ` for backward compatibility. When ` true ` , generates
152- separate ` pyi_deps ` . Imports in blocks with the format
150+ attribute. When ` true ` (default), generates separate ` pyi_deps ` . When
151+ ` false ` , type-checking dependencies are merged into ` deps ` . Imports in
152+ blocks with the format
153153 ` if typing.TYPE_CHECKING: ` or ` if TYPE_CHECKING: ` and type-only stub
154154 packages (eg. boto3-stubs) are recognized as type-checking dependencies.
155- * Default: ` false `
155+ * Default: ` true `
156156 * Allowed Values: ` true ` , ` false `
157157
158158[ ` # gazelle:python_generate_pyi_srcs bool ` ] ( #directive-python-generate-pyi-srcs )
159159: Controls whether to generate a ` pyi_srcs ` attribute if a sibling ` .pyi ` file
160- is found. When ` false ` (default) , the ` pyi_srcs ` attribute is not added.
161- * Default: ` false `
160+ is found. When ` false ` , the ` pyi_srcs ` attribute is not added.
161+ * Default: ` true `
162162 * Allowed Values: ` true ` , ` false `
163163
164164[ ` # gazelle:python_generate_proto bool ` ] ( #directive-python-generate-proto )
@@ -681,10 +681,42 @@ that are relative to the current package.
681681{gh-pr}` 3014 `
682682:::
683683
684- :::{error}
685- Detailed docs are not yet written.
684+ :::{versionchanged} VERSION_NEXT_FEATURE
685+ The default was changed from ` false ` to ` true ` . {gh-pr} ` 3753 `
686686:::
687687
688+ When ` true ` , Gazelle writes type-checking dependencies to the ` pyi_deps `
689+ attribute instead of merging them into ` deps ` . This is the default behavior.
690+
691+ Gazelle treats imports inside ` if TYPE_CHECKING: ` and
692+ ` if typing.TYPE_CHECKING: ` blocks as type-checking dependencies. It also adds
693+ type stub packages, such as ` boto3-stubs ` , to ` pyi_deps ` when the corresponding
694+ runtime package is imported normally.
695+
696+ For example, assume you have the following file:
697+
698+ ``` python
699+ import boto3
700+ from typing import TYPE_CHECKING
701+
702+ if TYPE_CHECKING :
703+ import requests
704+ ```
705+
706+ The generated target will be:
707+
708+ ``` starlark
709+ py_library(
710+ name = " foo" ,
711+ srcs = [" foo.py" ],
712+ pyi_deps = [" @pip//requests" ],
713+ deps = [" @pip//boto3" ],
714+ )
715+ ```
716+
717+ When ` false ` , Gazelle merges type-checking dependencies into ` deps ` and does
718+ not write ` pyi_deps ` .
719+
688720
689721(directive-python-generate-pyi-srcs)=
690722## ` python_generate_pyi_srcs `
@@ -693,6 +725,10 @@ Detailed docs are not yet written.
693725{gh-pr}` 3356 `
694726:::
695727
728+ :::{versionchanged} VERSION_NEXT_FEATURE
729+ The default was changed from ` false ` to ` true ` . {gh-pr}` 3753 `
730+ :::
731+
696732When ` true ` , include any sibling ` .pyi ` files in the ` pyi_srcs ` target attribute.
697733
698734For example, assume you have the following files:
0 commit comments