deprecateTypingAliases incorrectly reports Optional as deprecated
- Dominant language
- Python
- Stars
- 15.6k
- Forks
- 1.8k
- Avg merge
- 12h 13m
- Merged PRs (30d)
- 52
Description
I know this issue has been [discussed before](https://github.com/microsoft/pyright/issues/9793), however I think that one point is left undiscussed.
The issue:
Using `Optional`:
```pyhton
from typing import Optional
```
results in: `This type is deprecated as of Python 3.10; use "| None" instead (reportDeprecated)`
However it is [not deprecated](https://docs.python.org/3/library/typing.html#deprecated-aliases).
The reason that pyright currently reports this as deprecated seems to be based on [a comment by a python core dev on the python forums](https://discuss.python.org/t/clarification-for-pep-604-is-foo-int-none-to-replace-all-use-of-foo-optional-int/26945/6), and I think he makes a valid point.
However, python users usually wont visit the python forums, and would consult the official docs instead. That is where the confusion arises, because [those docs ](https://docs.python.org/3/library/typing.html#typing.Optional) does not have any wording that may indicate that the feature is deprecated, or even discouraged. This results in users questioning there sanity and/or no longer trust there tools (pyright in this case).
Therefore I would suggest:
1) Rephrase the error to something like: `While Optional is not specifically deprecated, it's recommended to use int | None instead`
2) Moving the rule away from the `deprecateTypingAliases` setting to a (new?) ` suggestedTypeAliases` (or something like that) setting.
Contributor guide
Research direction
Start by reproducing the Optional diagnostic with the deprecateTypingAliases setting enabled, then trace how that setting classifies typing aliases. Compare the behavior with the official typing documentation and the issue's proposed suggestedTypeAliases alternative. Done means the diagnostic wording and configuration behavior clearly distinguish deprecation from a recommendation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100