Skip to content

false positive bad-reversed-sequence when used with dicts #3940

Closed
@jnsnow

Description

@jnsnow

Steps to reproduce

reproducer.py:

"""false positive: bad-reversed-sequence"""
x = {'hello': 'world'}
for key in reversed(x):
    print(key)
> pylint reproducer.py

************* Module reproducer
reproducer.py:3:11: E0111: The first reversed() argument is not a sequence (bad-reversed-sequence)

Current behavior

Using a dictionary with reversed() causes a bad-reversed-sequence error to be emitted.

Expected behavior

This is fine in Python 3.7 and up, where dictionaries have a known order. Though they are not Sequence types as such, they do implement the __reversed__ method.

pylint --version output

pylint 2.6.0
astroid 2.4.2
Python 3.8.6 (default, Sep 25 2020, 00:00:00)
[GCC 10.2.1 20200723 (Red Hat 10.2.1-1)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug 🪲False Positive 🦟A message is emitted but nothing is wrong with the codeGood first issueFriendly and approachable by new contributors

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions