astral-sh/ruff

Split UP035 (deprecated-import) for aliases

Open

#7,436 opened on Sep 16, 2023

View on GitHub
 (3 comments) (0 reactions) (0 assignees)Rust (47,527 stars) (2,088 forks)batch import
help wantedrule

Description

I'd like to request the deprecated-import rule be split in two. Currently UP035 flags two different kinds of deprecations:

  • Names that have been moved, with a deprecated alias. Examples:
    • collections.* => collections.abc.*
    • {pipes => shlex}.quote
  • Types that are deprecated, considered equivalent by type checkers, but are different runtime values.
    • This is everything in the typing, typing_extensions and mypy_extensions modules.

For the former group, fixing them is significantly safer, since the only visible side-effects would be that a module wasn't imported (in the case of pipes), and a lack of a DeprecationWarning. It'd be rare for code to depend on those side-effects. The latter group can potentially be an unsafe change if something tries to observe the types directly at runtime though.

Ultimately I'd like to be able to autofix the moved names, whilst being able to separately flag (with a suggested fix) the typing changes that would be observable at runtime.

Contributor guide