This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author abarnert
Recipients abarnert, abarry, curioswati, r.david.murray, rhettinger
Date 2015-12-17.05:46:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1450331165.45.0.329682692305.issue25864@psf.upfronthosting.co.za>
In-reply-to
Content
@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.
History
Date User Action Args
2015-12-17 05:46:05abarnertsetrecipients: + abarnert, rhettinger, r.david.murray, abarry, curioswati
2015-12-17 05:46:05abarnertsetmessageid: <1450331165.45.0.329682692305.issue25864@psf.upfronthosting.co.za>
2015-12-17 05:46:05abarnertlinkissue25864 messages
2015-12-17 05:46:04abarnertcreate