Andrew Barnert added the comment:

@Swati Jaiswal:
> But the work around suggested here ...  is also not a general solution, i.e. 
> ... for any other mapping which does not have 0 as a key, it results in 
> KeyError.

You're missing the point. The workaround isn't intended to be a general 
solution to making mappings reversible. It's intended to produce the exact same 
behavior as the current design, for any code that somehow depends on that. So, 
any mapping that happens to be reversible by luck is reversible with the 
workaround; any mapping that successfully produces odd nonsense produces the 
same odd nonsense; any mapping that raises a KeyError(0) will raise the same 
KeyError(0).

In the incredibly vast majority of cases (probably 100%) you will not want that 
workaround; you will want the new behavior that raises a TypeError instead. I 
don't think the workaround needs to be mentioned in the documentation or 
anything; I just produced it to prove that, on the incredibly unlikely chance 
that the change is a problem for someone, the workaround to restore the old 
behavior is trivial.

Meanwhile, your general solution takes linear space, and linear up-front work, 
which makes it unacceptable for a general __reversed__ implementation. When you 
actually want, you can do it manually and explicitly in a one-liner, as already 
explained in the docs.

If you're still not getting this, pretend I never mentioned the workaround. It 
really doesn't matter.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25864>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to