Skip to content

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

Closed
@phy1729

Description

@phy1729

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    AstroidRelated to astroidFalse Positive 🦟A message is emitted but nothing is wrong with the codeinference

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions