Skip to content

UP010 should not report future features as unnecessary if they are used #19561

@dscorbett

Description

@dscorbett

Summary

If a feature imported from __future__ is used later in the module, it is not unnecessary, so unnecessary-future-import (UP010) should not flag it. Example:

$ cat >up010.py <<'# EOF'
from __future__ import print_function
print(print_function)
# EOF

$ python up010.py
_Feature((2, 6, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 1048576)

$ ruff --isolated check up010.py --select UP010 --fix
Found 1 error (1 fixed, 0 remaining).

$ python up010.py 2>&1 | tail -n 1
NameError: name 'print_function' is not defined

This also applies to reexports using __all__ like this:

from __future__ import print_function
__all__ = ["print_function"]

Version

ruff 0.12.5 (d13228a 2025-07-24)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions