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 bad-reversed-sequence when used with dicts #3940

Closed
jnsnow opened this issue Nov 10, 2020 · 2 comments · Fixed by #3958, tingvarsson/telegram.ongabot#33 or hypothesis/checkmate#227
Labels
Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code Good first issue Friendly and approachable by new contributors

Comments

@jnsnow
Copy link

jnsnow commented Nov 10, 2020

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)]

@hippo91
Copy link
Contributor

hippo91 commented Nov 19, 2020

@jnsnow thanks for the report. I can reproduce it.

@hippo91 hippo91 added Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code Good first issue Friendly and approachable by new contributors labels Nov 19, 2020
@hippo91
Copy link
Contributor

hippo91 commented Nov 19, 2020

For anyone wanting to make a first contribution, take a look at the base.py module, in the method _check_reversed.

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