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 rhettinger
Recipients Zahari.Dim, rhettinger, serhiy.storchaka
Date 2018-09-11.00:28:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1536625736.57.0.0269046726804.issue34586@psf.upfronthosting.co.za>
In-reply-to
Content
I've discussed this with other core devs and spent a good deal of time evaluating this proposal.  I'm going to pass on the this one but do think it was a inspired suggestion.  Thank you for the proposal.

----------

Note, the original get_where() recipe has an issue.  Upon successful lookup, it returns a 2-tuple but on failure it calls __missing__ which typically returns a scalar (if it doesn't raise an exception).

The proposed use case is plausible but rare.  As Serhiy mentioned, it is also reasonable for the user to write their own loops over the *maps* attribute.  That loop can have subtleties but it is better to let the user choose between try/except semantics and if-else semantics according to the use case.

FWIW, I tried out several variants of the proposal including "cm.index(key) -> int" and "cm.search(key) -> mapping".  Each of the variants had some awkwardness when trying to use it there didn't seem to be a variant that was a net win.
History
Date User Action Args
2018-09-11 00:28:56rhettingersetrecipients: + rhettinger, serhiy.storchaka, Zahari.Dim
2018-09-11 00:28:56rhettingersetmessageid: <1536625736.57.0.0269046726804.issue34586@psf.upfronthosting.co.za>
2018-09-11 00:28:56rhettingerlinkissue34586 messages
2018-09-11 00:28:55rhettingercreate