Skip to content

Commit 007128a

Browse files
committed
add python typing tools
1 parent f5d4dca commit 007128a

1 file changed

Lines changed: 44 additions & 3 deletions

File tree

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

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,29 @@ 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 dynamically typed language, meaning variable types don't require explicit declaration. However, as projects grow in complexity, type annotations become increasingly valuable for code maintainability and clarity.
16+
17+
Type hints have been a major focus of recent Python releases, and I was particularly intrigued when I heard about [Guido van Rossum's work on MyPy at Dropbox](https://blog.dropbox.com/topics/company/thank-you--guido), where the team needed robust tooling to migrate their codebase from Python 2 to Python 3.
18+
19+
Today, type hints are essential for modern Python development. They significantly enhance IDE capabilities and AI-powered development tools by providing better code completion, static analysis, and error detection. This mirrors the evolution we've seen with TypeScript's adoption over traditional JavaScript—explicit typing leads to more reliable and maintainable code.
20+
21+
<!-- more -->
22+
1323
## typing module vs collections module
1424

1525
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.
1626

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

19-
<!-- more -->
20-
2129
### Aliases to Built-in Types
2230

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

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

120-
## To be continued
128+
## Typing tools
129+
130+
### MyPy
131+
132+
Ref. MyPy in [this post](../2021/2021-01-04-python-lint-and-format.md#mypy).
133+
134+
### Pyright && Pylance
135+
136+
Ref. Pyright in [this post](../2021/2021-01-04-python-lint-and-format.md#pyright).
137+
138+
[Pylance](https://github.com/microsoft/pylance-release#readme) is the Microsoft backed Pyright extension for VSCode.
139+
140+
### RightTyper
141+
142+
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.
143+
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.
144+
145+
### ty
146+
147+
[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.
148+
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).
149+
150+
While Ruff excels at various aspects of Python linting, type checking remains outside its scope.
151+
ty aims to fill this gap, though it's currently in preview and still evolving toward production readiness.
152+
The combination of Ruff and ty promises to provide a comprehensive Python code quality toolkit.
153+
154+
### pyrefly
155+
156+
[pyrefly](https://pyrefly.org/) emerges as another promising entrant in the Python type checking landscape.
157+
Developed by Meta and also written in Rust, pyrefly offers both type checking capabilities and language server functionality.
158+
While still in preview, it demonstrates the growing trend of high-performance Python tooling implemented in Rust.
159+
160+
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.
161+
Its backing by Meta suggests potential for robust development and long-term support.

0 commit comments

Comments
 (0)