dictproxy should be recognised as a mapping, not a sequence

Issue #2601 resolved
Ronan Lamy
created an issue

On CPython:

>>> type(int.__dict__)
<type 'dictproxy'>
>>> reversed(int.__dict__)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: argument to reversed() must be a sequence

On PyPy:

>>>> type(int.__dict__)
<type 'dictproxy'>
>>>> reversed(int.__dict__)
<reversed object at 0x00007f2ada27ec08>

This was fixed for pypy3 in 78dee6627756, but backporting that commit isn't enough to fix pypy2.

Comments (3)

  1. Armin Rigo

    That's because pypy2 has a method dict.__reversed__() that raises argument to reversed() must be a sequence. In pypy3 dict no longer has one, and instead reversed() checks something. It looks wrong in py3.5 too, btw: it seems that it wouldn't accept user-defined sequences.

    ..never mind, read a condition wrongly. I'm unsure why there are two checks for the type of w_sequence. I think the second one (the one in __init__()) cannot possibly fail after the first one (the issequence_w() in descr___new_2()) passes.

  2. Log in to comment