Skip to content

Commit c92729f

Browse files
Update docs on strict mode
Update docs on strict mode with more explanation of when to/not to use it. Include link in template prompt.
1 parent 5aaa764 commit c92729f

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

copier.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ strict_typing:
129129
default: false
130130
help: |
131131
Would you like to run pyright in strict mode?
132-
It is excellent for building consistent, maintainable projects but difficult to adopt on top
133-
of legacy code and projects with many external dependencies.
134132
The recommended approach is to start with strict mode and disable it if it
135-
becomes too costly to maintain.
133+
becomes too costly to maintain.
134+
See https://diamondlightsource.github.io/python-copier-template/main/how-to/strict-mode.html
135+
for more information.
136136
137137
pypi:
138138
type: bool

docs/how-to/strict-mode.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
# Enable Pyright's Strict Mode
1+
# Use Pyright's Strict Mode
22

3-
For projects using pyright you can enable strict mode for stricter than normal type checking. See [the docs](https://github.com/microsoft/pyright/blob/main/docs/configuration.md) for a full breakdown. The primary benefits are increased confidence in code that has been more thoroughly analyzed and a shorter development time thanks to fast feedback from the type checker.
3+
For projects using pyright you can enable strict mode for stricter than normal type checking. See [the docs](https://github.com/microsoft/pyright/blob/main/docs/configuration.md) for a full breakdown.
44

5-
## Configuration
5+
## How to Enable
66

7-
Change the `typeCheckingMode` line to `"strict"` in `pyproject.toml` as follows:
7+
When creating a template, select `pyright` as the type checker and type `y` when prompted to enable strict mode.
88

9-
```toml
10-
[tool.pyright]
11-
typeCheckingMode = "strict"
12-
reportMissingImports = false # Ignore missing stubs in imported modules
13-
```
9+
## Who Should Use Strict Mode?
1410

15-
## Third Party Libraries
11+
Strict mode enforces good practices such as type hints on function signatures, providing increased confidence in code that has been more thoroughly analyzed and a shorter development time thanks to fast feedback from the type checker. Starting a new project and continually keeping it passing provides a long-term benefit when it comes to maintanability and robustness. However, adopting strict mode on top of legacy projects is likely to lead to lots of errors to work through - probably thousands. Additionally it does not usually work well with libraries that do not have [type stubs](https://github.com/microsoft/pyright/blob/main/docs/type-stubs.md), you will likely need a `# type: ignore` on any line that directly uses the library code. This may limit the usefulness of pyright but it can still be worth doing to ensure your own code is internally consistent.
1612

17-
Strict mode does not usually work well with libraries that do not have [type stubs](https://github.com/microsoft/pyright/blob/main/docs/type-stubs.md), you will likely need a `# type: ignore` on any line that directly uses the library code. This may limit the usefulness of pyright but it can still be worth doing to ensure your own code is internally consistent.
13+
The recommended approach for brand new projects is to enable strict mode and stick with it for as long as is practical, moving away if it starts to cause more hinrance than help (e.g. because too many major dependencies do not support it).

0 commit comments

Comments
 (0)