Skip to content

typing_extensions.Literal reimport is not "detected" #1744

@ashb

Description

@ashb

As part of the Airflow project we have an airflow.typing_compat module that has this in it https://github.com/apache/airflow/blob/71306b31f1842ee2b1eb1cc2980b90f0fb6b11dc/airflow/typing_compat.py#L38-L41:

if sys.version_info >= (3, 9):
    from typing import Literal
else:
    from typing_extensions import Literal

Ruff right now doesn't detect this use of Literal and tries to resolve the value inside it as a type:

% echo 'from airflow.typing_compat import Literal; from typing import Union; X = Union[Literal[False], Literal["db"]]' | \
  ruff - --line-length=999
-:1:104: F821 Undefined name `db`

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