Skip to content

Commit 82eb01c

Browse files
committed
docs: add tips & tricks section, beginning with solutions for the TYPE_CHECKING constant
1 parent ee90255 commit 82eb01c

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

docs/tips.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Tips and Tricks
2+
3+
## TYPE_CHECKING
4+
5+
Do you use `TYPE_CHECKING` in bricks? `TYPE_CHECKING` is a special constant that is `True` for static type checkers,
6+
but `False` at runtime.
7+
8+
Example:
9+
``` python
10+
if TYPE_CHECKING:
11+
from mypy_boto3_s3.service_resource import Object as S3Object
12+
```
13+
14+
The `poly check` command will identify the import and expect it to be defined as a dependency.
15+
Usually, these dev-specific dependencies are added as dev-dependencies (and that is correct).
16+
17+
This means that the `poly check` command will report it as a missing dependency.
18+
19+
20+
### Solution
21+
To resolve this, you can add _optional dependencies_ in the projects that use the brick with the TYPE_CHECKING constant.
22+
23+
Example, using the dev-only "boto3-stubs" library:
24+
``` python
25+
# add the dev-dependencies for every project that is using the brick
26+
[project.optional-dependencies]
27+
local-dev = ["boto3-stubs[s3]"]
28+
```

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ nav:
1818
- "Examples & Production Systems": examples.md
1919
- "Videos & tutorials": videos.md
2020
- "Configuring your Python IDE": ide.md
21+
- "Tips & Tricks": tips.md
2122
- "About this Open Source Project": about.md
2223

2324
theme:

0 commit comments

Comments
 (0)