Skip to content

deprecateTypingAliases incorrectly reports Optional as deprecated #11275

@roel-gerrits

Description

@roel-gerrits

I know this issue has been discussed before, however I think that one point is left undiscussed.

The issue:

Using Optional:

from typing import Optional

results in: This type is deprecated as of Python 3.10; use "| None" instead (reportDeprecated)

However it is not deprecated.

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, 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 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions