python / python/mypy

mypy suggests deprecated code

Open
#16,815 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-pep-585
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

To Reproduce

def function(arg: Callable[[], Iterable[int]]) -> Set[int]: return set()

Expected Behavior
error: Name "Callable" is not defined [name-defined]
error: Name "Iterable" is not defined [name-defined]
error: Name "Set" is not defined [name-defined]
and perhaps something like
(for Callable) note: Did you forget to import it from from "collections.abc"? (Suggestion: "from collections.abc import Callable")
(for Iterable) note: Did you forget to import it from from "collections.abc"? (Suggestion: "from collections.abc import Iterable")
(for Set) note: Use set[int] if the set is mutable or import Set from collections.abc if the set is immutable: "from collections.abc import Set"

Actual Behavior

error: Name "Callable" is not defined  [name-defined]
note: Did you forget to import it from "typing"? (Suggestion: "from typing import Callable")
error: Name "Iterable" is not defined  [name-defined]
note: Did you forget to import it from "typing"? (Suggestion: "from typing import Iterable")
error: Name "Set" is not defined  [name-defined]
note: Did you forget to import it from "typing"? (Suggestion: "from typing import Set")

typing.Callable, typing.Iterable, and typing.Set were all deprecated (python 3.9+)

Your Environment

  • Mypy version used: 1.8.0 (compiled: yes)
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.11.6

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the provided snippet using mypy 1.8.0 on Python 3.11.6, then trace the diagnostic suggestion handling for undefined Callable, Iterable, and Set names. Done means the suggestions no longer recommend deprecated typing imports and instead identify the appropriate collections.abc or built-in forms, with regression coverage for the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.