Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated typing imports #6720

Closed
erlingstaff opened this issue Apr 23, 2024 · 2 comments · Fixed by #6726
Closed

Remove deprecated typing imports #6720

erlingstaff opened this issue Apr 23, 2024 · 2 comments · Fixed by #6726

Comments

@erlingstaff
Copy link
Contributor

erlingstaff commented Apr 23, 2024

Description

Several imports from typing are deprecated, and should be either:

  1. Removed in favor of builtins, ex: typing.Dict -> dict
  2. Re-imported from another module, ex: from typing import Callable ->
    from collections.abc import Callable

The deprecations are relevant in Python versions ranging from 3.8 -> 3.12. This issue focuses on the imports deprecated in 3.8 or 3.9, as 3.9 is the minimum Python needed to run Rucio (as outlined in setup_rucio.py). When Rucio is updated, there might be new deprecations.

The following grep command finds all (i think) instances of deprecated imports:

grep -R --include="*.py" -E "from typing import.*(Callable|Iterator|Iterable|Sequence|AbstractSet|Dict|Tuple|List|Set|Type|FrozenSet|Tuple|DefaultDict|OrderedDict|ChainMap|Counter|Deque|AbstractSet|Collection|Container|ItemsView|KeysView|Mapping|MappingView|MutableMapping|MutableSet|MutableSequence|ValuesView|Corutine|AsyncGenerator|AsyncIterable|AsyncIterator|Awaitable|Generator|Reversible|ContextManager|AsyncContextManager|Match|Pattern)(,| )" .

This currently returns

image

More info:
https://docs.python.org/3/library/typing.html#deprecated-aliases
https://peps.python.org/pep-0585/#implementation

Motivation

  1. Standardize imports
  2. Avoid DeprecationWarnings and larger changes in the future

Change

  1. Find all deprecated imports from typing, either manually or automatically using e.g. the aforementioned grep command
  2. Change as appropriate
@erlingstaff erlingstaff changed the title Removed deprecated typing imports Remove deprecated typing imports Apr 23, 2024
@dchristidis
Copy link
Contributor

We’ve already had #6276 and I’m guessing that they may be accidentally reintroduced again in the future. Could you investigate the use of Ruff?

@rdimaio
Copy link
Contributor

rdimaio commented Apr 23, 2024

We’ve already had #6276 and I’m guessing that they may be accidentally reintroduced again in the future. Could you investigate the use of Ruff?

Good catch on Ruff having this functionality - I'm configuring Ruff to include a few more features, I'll assign this issue to myself to look into adding this too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment