Deprecate type comment support?
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
I've kicked off a discussion on typing-sig, as some of you have already seen, to talk about deprecating and eventually removing type comments.
Currently, the ast module takes type_comments=True to enable parsing any type comment.
I am proposing that this argument emit deprecation warnings with Python 3.12 and 3.13. With Python 3.14 type_comments=True will be removed, and all type comments except for # type: ignore will be treated as normal comments. (# type: ignore will always parse as its own node in the parser).
There is a complication: ast.parse also accepts feature_version. 3.11 is not EOL until 2027, so if someone wanted to parse code written targeting 3.11 with a mypy running on, say 3.14, that would not work under my proposal. I believe that this is acceptable, because the user would have 2 reasonable alternatives: 1) type check their code targeting 3.11 with mypy running on 3.11 2) update to type annotations, which they will need to do eventually anyway, and would have 3 years to do so already.
I think the existing tooling such as libcst, pyupgrade, com2ann, etc make the upgrade relatively straight forward.
I'd be interested to hear what others think mypy should do in regards to removing support for type comments (or if we should at all!)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked typing-sig discussion and the issue's proposal for ast.parse(type_comments=True) and feature_version behavior. Determine whether mypy should remove type-comment support and what compatibility policy is expected; done requires an agreed decision and corresponding implementation scope.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100