You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Update 2023-05-21: Replaced flake8, pylint, black and isort by [ruff](https://github.com/charliermarsh/ruff). When replacing pylint, should [add check by mypy](https://beta.ruff.rs/docs/faq/#how-does-ruff-compare-to-pylint).
25
26
- Update 2023-11-07: Bandit could be replaced by ruff too with the support of flake-bandit.
27
+
- Update 2025-08-31: [Ty or Pyrefly](../2025/2025-02-01-python-type-hints.md#typing-tools) (both written in Rust) could be used for type checking.
26
28
27
29
!!! note
28
30
The only thing ruff can't do at the moment is [type checking](https://docs.astral.sh/ruff/faq/#how-does-ruff-compare-to-mypy-or-pyright-or-pyre).
For `pip install` users, try [uv pip install](https://github.com/astral-sh/uv) from the same author of ruff.
48
+
For `pip install` users, try [uv pip install](https://github.com/astral-sh/uv) from the same author of ruff.[uv cheat sheet here](../2025/2025-08-26-python-uv-cheat-sheet.md).
47
49
48
50
A highly opinionated and subjective perspective, but finally, we have a real competitor (or even a replacement) of `pip install`. If you have a private PyPi index, all you need to setup is `export UV_DEFAULT_INDEX=$PIP_INDEX_URL`; otherwise, just add `uv` before `pip install` command.
49
51
@@ -162,8 +164,54 @@ Found 0 vulnerabilities in 214 packages
162
164
163
165
Github has already provided, free of charge, the [vulnerable dependencies alert](https://docs.github.com/en/code-security/supply-chain-security/managing-vulnerabilities-in-your-projects-dependencies/about-alerts-for-vulnerable-dependencies).
164
166
167
+
### mypy
168
+
169
+
!!! note
170
+
While mypy is significantly less performant than [modern typing tools written in Rust](../2025/2025-02-01-python-type-hints.md#typing-tools), it remains the gold standard for type checking in Python. As of September 2025, all Rust-based typing tools are still in preview stage.
171
+
172
+
For projects using SQLAlchemy, consider installing the `sqlalchemy-stubs` plugin to handle SQLAlchemy's dynamic class generation. And also django-stubs, pandas-stubs, types-setuptools, types-requests etc.
173
+
174
+
Just some personal notes on mypy, though [this post](../2025/2025-02-01-python-type-hints.md) based on the official MyPy documentation.
ignore_missing_imports = True # We recommend using this approach only as a last resort: it's equivalent to adding a # type: ignore to all unresolved imports in your codebase.
181
+
plugins = sqlmypy # sqlalchemy-stubs
182
+
exclude = (?x)(
183
+
^venv
184
+
| ^build
185
+
)
186
+
```
187
+
188
+
running mypy:
189
+
190
+
```bash
191
+
mypy .
192
+
mypy . --exclude [a regular expression that matches file path]
193
+
mypy . --exclude venv[//] # exclude venv folder under the root
194
+
```
195
+
196
+
!!! warning
197
+
When using mypy, it would be better to use mypy against to [all files in the project](https://github.com/python/mypy/issues/13916), but not some of them.
198
+
199
+
#### Auto discover missing stub files
200
+
201
+
```bash
202
+
# search available stubs, and ask for installation,
203
+
# that can be used to declared the stub packages into requirements files.
204
+
mypy --install-types .
205
+
206
+
# for local quick test, we might not care about the requirements files.
207
+
mypy --install-types --non-interactive .
208
+
```
209
+
165
210
### pyright
166
211
212
+
!!! warning
213
+
Replaced by [ty](#ty). More info about Python typing tools in this [post](../2025/2025-02-01-python-type-hints.md#typing-tools)
ignore_missing_imports = True # We recommend using this approach only as a last resort: it's equivalent to adding a # type: ignore to all unresolved imports in your codebase.
223
-
plugins = sqlmypy # sqlalchemy-stubs
224
-
exclude = (?x)(
225
-
^venv
226
-
| ^build
227
-
)
228
-
```
229
-
230
-
running mypy:
231
-
232
-
```bash
233
-
mypy .
234
-
mypy . --exclude [a regular expression that matches file path]
235
-
mypy . --exclude venv[//] # exclude venv folder under the root
236
-
```
237
-
238
-
!!! warning
239
-
240
-
When using mypy, it would be better to use mypy against to [all files in the project](https://github.com/python/mypy/issues/13916), but not some of them.
241
-
242
-
#### Auto discover missing stub files
243
-
244
-
```bash
245
-
# search available stubs, and ask for installation,
246
-
# that can be used to declared the stub packages into requirements files.
247
-
mypy --install-types .
248
-
249
-
# for local quick test, we might not care about the requirements files.
250
-
mypy --install-types --non-interactive .
251
-
```
252
-
253
260
### pylyzer
254
261
262
+
!! warning
263
+
Replaced by [ty](#ty). The author is working for ty now. More info about Python typing tools in this [post](../2025/2025-02-01-python-type-hints.md#typing-tools).
264
+
255
265
A fast, feature-rich static code analyzer (type checker) & language server forPython writtenin Rust. A possible mypy, pyright replacement in the future, currently it's still in the [early stage](https://github.com/mtshiba/pylyzer/issues/59#issuecomment-1851284715).
256
266
257
267
pylyzer [converts Python ASTs to Erg ASTs](https://github.com/mtshiba/pylyzer#how-it-works) and passes them to Erg's type checker. It then displays the results with appropriate modifications.
Fast, feature-rich static code analyzer (type checker) & language server forPython writtenin Rust. It also has a competitor called [pyrefly](https://pyrefly.org/) from Meta. As of September 2025, both are in preview stage yet.
280
+
281
+
More info about Python typing tools in this [post](../2025/2025-02-01-python-type-hints.md#typing-tools)
Hereunder an example of `.pre-commit-config.yaml` file in my [fastapi-demo](https://github.com/copdips/fastapi-demo/blob/main/.pre-commit-config.yaml) repo.
0 commit comments