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

unused-import false positive for names in string argument to typing.cast #7548

Open
lggruspe opened this issue Oct 1, 2022 · 3 comments
Open
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@lggruspe
Copy link
Contributor

lggruspe commented Oct 1, 2022

Bug description

example.py:

# pylint: disable=missing-docstring
from pathlib import Path
import typing as t

paths = t.cast("set[Path]", set())

Configuration

No response

Command used

pylint example.py

Pylint output

************* Module example
example.py:2:0: W0611: Unused Path imported from pathlib (unused-import)

------------------------------------------------------------------
Your code has been rated at 6.67/10 (previous run: 6.67/10, +0.00)

Expected behavior

There shouldn't be any messages.

Pylint version

pylint 2.15.3
astroid 2.12.10
Python 3.10.7 (main, Sep  7 2022, 00:00:00) [GCC 12.2.1 20220819 (Red Hat 12.2.1-1)]

OS / Environment

fedora 36

Additional dependencies

No response

@lggruspe lggruspe added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Oct 1, 2022
@Pierre-Sassoulas Pierre-Sassoulas added Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Oct 1, 2022
@clavedeluna
Copy link
Contributor

I'm able to reproduce. Worth noting, though, that even PyCharm registers Path as unused

@Pierre-Sassoulas Pierre-Sassoulas added False Positive 🦟 A message is emitted but nothing is wrong with the code Needs decision 🔒 Needs a decision before implemention or rejection and removed Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine labels Nov 8, 2022
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.17.0 milestone Nov 8, 2022
@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 2.17.0, 3.0.0 Feb 1, 2023
@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 3.0.0, 4.0.0 Sep 25, 2023
@bersbersbers
Copy link

This false positive is prone to receiving much additional exposure now that ruff has implemented TC006, compare astral-sh/ruff#14511, leading to the stringification of the type argument in practically all cast calls.

TC006 is still in preview mode, but that won't have to remain that way. https://docs.astral.sh/ruff/rules/runtime-cast-value/

@Pierre-Sassoulas Pierre-Sassoulas added Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs decision 🔒 Needs a decision before implemention or rejection labels Jan 8, 2025
@Pierre-Sassoulas Pierre-Sassoulas removed this from the 4.0.0 milestone Jan 8, 2025
@Pierre-Sassoulas
Copy link
Member

Nice catch @bersbersbers thank you. This check has to be activated in ruff so it's not going to be a flash flood, but I labelled as "need PR".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

No branches or pull requests

4 participants