Skip to content

Importing a function called cast leads to confusing F722 and F821 errors #490

@tgross35

Description

@tgross35

Using a function named cast (shadows a newish builtin) leads to somewhat confusing errors. For the test file:

from something import cast
# same with `def cast(s): pass`

abc = "123"
cast(f"tuv {abc} xyz")

We get the following unexpected results:

$ ruff tmp.py 
Found 2 error(s).
tmp.py:5:6: F722 Syntax error in forward annotation: ` xyz`
tmp.py:5:6: F821 Undefined name `tuv`

I'm not quite sure what the best resolution is, maybe a warning on imports/defs that shadow cast?

Metadata

Metadata

Assignees

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