mirror of
https://github.com/astral-sh/ruff
synced 2026-01-22 05:51:03 -05:00
## Summary The fix for PYI025 is currently marked as unsafe in non-global scopes for both `.py` and `.pyi` files, on the grounds that all global-scope symbols in Python are implicitly exported from the module, so changing the name of something in the global scope could break other modules that import the module we're fixing. Unlike in `.py` files, however, imported symbols are never implicitly re-exported from stub files. Symbols are only understood by static analysis tools as being re-exported from stubs if they are marked as explicit re-exports, which take three forms: ```py from foo import * # all symbols from foo are re-exported from the stub # the "redundant" alias marks it as an explicit re-export # (note that the alias needs to be identical to the symbol's "actual" name # in order for it to be a re-export) from bar import barrr as barrr # inclusion in __all__ also marks it as an explicit re-export, # just like in `.py` files from baz import bazzz __all__ = ["bazzz"] ``` This is [specc'd in PEP 484](https://peps.python.org/pep-0484/#stub-files), and means that we can mark the fix for PYI025 as safe in more cases for `.pyi` files. ## Test Plan `cargo test`. An existing test case goes from being an unsafe fix to a safe fix in a `.pyi` fixture. I also added a new fixture so we have coverage of global-scope imports that are marked as re-exports using "redundant" `from collections.abc import Set as Set` aliases.