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

False positive not-a-mapping with cast and TypeVar #8074

Closed
phy1729 opened this issue Jan 17, 2023 · 3 comments · Fixed by pylint-dev/astroid#1982, pylint-dev/astroid#2158 or pylint-dev/astroid#2303
Labels
Astroid Related to astroid False Positive 🦟 A message is emitted but nothing is wrong with the code inference
Milestone

Comments

@phy1729
Copy link

phy1729 commented Jan 17, 2023

Bug description

The following code results in a false positive. (The type hints may be removed; however, the cast and dummy assignment may not).

"""Docstring."""
from typing import TypeVar
from typing import cast


T = TypeVar('T')


def ident(thing: T) -> T:
    """Return thing."""
    return cast(T, thing)


_ = ident([])
dict(**ident({}))

Configuration

No response

Command used

pylint bug.py

Pylint output

************* Module bug
bug.py:15:7: E1134: Non-mapping value ident({}) is used in a mapping context (not-a-mapping)

Expected behavior

No error should be produced.

Pylint version

pylint 2.15.10
astroid 2.13.2
Python 3.10.9 (main, Dec 15 2022, 18:25:35) [Clang 14.0.0 (clang-1400.0.29.202)]

OS / Environment

macOS 13

Additional dependencies

No response

@phy1729 phy1729 added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jan 17, 2023
@clavedeluna clavedeluna added False Positive 🦟 A message is emitted but nothing is wrong with the code and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jan 18, 2023
@clavedeluna
Copy link
Collaborator

clavedeluna commented Jan 18, 2023

worth mentioning that calling {**ident({})} does not cause this FP

also commenting out line _ = ident([]) makes the FP go away 🤔 so something is wrong with the inference here

@cdce8p
Copy link
Member

cdce8p commented Jan 28, 2023

Thanks for the report @phy1729! This will be fixed in pylint-dev/astroid#1982 and released probably with the next version.

@cdce8p cdce8p self-assigned this Jan 28, 2023
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.16.0 milestone Jan 29, 2023
@cdce8p
Copy link
Member

cdce8p commented Jan 31, 2023

The fixed cause a RecursionError to reappear. We are reverting the change for now.

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