Skip to content

Got F811 and F821 when indirectly importing Literal and overload #6969

@leavers

Description

@leavers

A minimal code snippet that reproduces the bug:

File test.py

from mytyping import Literal, overload
# from typing import Literal, overload
# from typing_extensions import Literal, overload

tag: Literal["a"] = "a"


@overload
def func(a: int):
    ...


@overload
def func(a: int, b: int):
    ...


def func(a: int, b: int = 0):
    return a, b

File mytyping.py:

from typing import Literal, overload

__all__ = ["Literal", "overload"]

When using ruff check with from mytyping import Literal, overload enabled, I got:

$ ruff check test.py
test.py:5:15: F821 Undefined name `a`
test.py:14:5: F811 Redefinition of unused `func` from line 9
test.py:18:5: F811 Redefinition of unused `func` from line 14
Found 3 errors.

However, when uncomment either typing or typing_extensions, ruff check does not report above errors.

Ruff version:

$ ruff --version
ruff 0.0.286

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-infoMore information is needed from the issue author

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions