Skip to content

Commit 6ac55a6

Browse files
committed
add python typing tools
1 parent f5d4dca commit 6ac55a6

1 file changed

Lines changed: 43 additions & 3 deletions

File tree

docs/posts/2025/2025-02-01-python-type-hints.md

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,28 @@ authors:
33
- copdips
44
categories:
55
- python
6+
- linter
67
comments: true
78
date:
89
created: 2025-02-01
10+
updated: 2025-06-28
911
---
1012

1113
# Python Type Hints
1214

15+
Python is a dynamic language, which means you don't need to declare the type of a variable. But in reality, once you go for some complexity previously (even for small project nowadays), you need to declare the type of a variable.
16+
One of biggest focus of recent Python releases is to improve the type hints. My first memory of typing hint is back to Guido when I heard about he started developing the MyPy module for Dropbox, who needed to migrated code base from Python 2 to Python 3. (Most of this team moved to Microsoft now.)
17+
Typing hint becomes more important when we start building applications (even scripts) with IDE, or using AI tools, typing hint help the IDE and AI to understand much better the code base, so provide better code completion, code analysis, etc.
18+
We can see the same thing in TypeScript vs traditional JavaScript.
19+
20+
<!-- more -->
21+
1322
## typing module vs collections module
1423

1524
Since Python 3.9, most of types in `typing` module is [deprecated](https://docs.python.org/3/library/typing.html#deprecated-aliases), and `collections` module is recommended.
1625

1726
Some types like: `typing.Any`, `typing.Generic`, `typing.TypeVar`, etc. are still not deprecated.
1827

19-
<!-- more -->
20-
2128
### Aliases to Built-in Types
2229

2330
| Deprecated Alias | Replacement |
@@ -117,4 +124,37 @@ Some types like: `typing.Any`, `typing.Generic`, `typing.TypeVar`, etc. are stil
117124

118125
!!! note "(Python 3.9+) Both `typing.Sequence` and `typing.Collection` are [deprecated aliases](#typing-module-vs-collections-module)."
119126

120-
## To be continued
127+
## Typing tools
128+
129+
### MyPy
130+
131+
Ref. MyPy in [this post](../2021/2021-01-04-python-lint-and-format.md#mypy).
132+
133+
### Pyright && Pylance
134+
135+
Ref. Pyright in [this post](../2021/2021-01-04-python-lint-and-format.md#pyright).
136+
137+
[Pylance](https://github.com/microsoft/pylance-release#readme) is the Microsoft backed Pyright extension for VSCode.
138+
139+
### RightTyper
140+
141+
During an internal tech demo at my working, I heard about [RightTyper](https://github.com/RightTyper/RightTyper), a Python tool that generates type annotations for function arguments and return values.
142+
It’s important to note that RightTyper doesn’t statically parse your Python files to add types; instead, it needs to run your code to detect types on the fly. So, one of the best ways to use RightTyper is with python `-m pytest`, assuming you have good test coverage.
143+
144+
### ty
145+
146+
[ty](https://github.com/astral-sh/ty) represents the next generation of Python type checking tools. Developed by the team behind the popular [ruff](https://docs.astral.sh/ruff/) linter, ty is implemented in Rust for exceptional performance.
147+
It functions both as a type checker and language server, offering seamless integration through its dedicated [VSCode extension ty-vscode](https://github.com/astral-sh/ty-vscode).
148+
149+
While Ruff excels at various aspects of Python linting, type checking remains outside its scope.
150+
ty aims to fill this gap, though it's currently in preview and still evolving toward production readiness.
151+
The combination of Ruff and ty promises to provide a comprehensive Python code quality toolkit.
152+
153+
### pyrefly
154+
155+
[pyrefly](https://pyrefly.org/) emerges as another promising entrant in the Python type checking landscape.
156+
Developed by Meta and also written in Rust, pyrefly offers both type checking capabilities and language server functionality.
157+
While still in preview, it demonstrates the growing trend of high-performance Python tooling implemented in Rust.
158+
159+
The tool integrates smoothly with modern development environments through its [VSCode extension refly-vscode](https://marketplace.visualstudio.com/items?itemName=meta.pyrefly), making it accessible to a wide range of developers.
160+
Its backing by Meta suggests potential for robust development and long-term support.

0 commit comments

Comments
 (0)