Skip to content

F821 on a Literal type that isn't directly imported by the current module #2105

@joerick

Description

@joerick

We're getting a F821 on a Literal type over in pypa/cibuildwheel#1405 . I've isolated this to the following-

Two files are needed-

script.py

from __future__ import annotations

from script_typing import Literal

testing_archs: list[Literal["x86_64", "arm64"]]
testing_archs = ['x86_64']
print(testing_archs)

script_typing.py

import sys

if sys.version_info < (3, 8):
    from typing_extensions import Literal
else:
    from typing import Literal

Here's what happens:

$ ruff --isolated --fix script.py 
script.py:5:29: F821 Undefined name `x86_64`
script.py:5:39: F821 Undefined name `arm64`
Found 2 error(s).

This happens without any pyproject.toml configuration

Version: ruff 0.0.230.

p.s. ruff seems pretty incredible! the speed 🤯

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions