Message10957

Author buelgsk8er
Recipients buelgsk8er
Date 2016-09-25.19:56:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1474833391.39.0.543279624299.issue2523@psf.upfronthosting.co.za>
In-reply-to
Content
How to reproduce
================

in CPython 2.7:

>>> from collections import defaultdict
>>> class FooError(Exception): pass
>>> def factory():
...     raise FooError()
>>> defaultdict(factory).__getitem__(123)
Traceback (most recent call last):
FooError

in Jython 2.7.1b3:

>>> from collections import defaultdict
>>> class FooError(Exception): pass
>>> def factory():
...     raise FooError()
>>> defaultdict(factory).__getitem__(123)
Traceback (most recent call last):
KeyError: 123


Rationale
=========

defaultdict functionality is the same as for the dict class except the
overriden method __missing__ and default_factory instance variable[1], so
d[key] operation should returns or raises whatever is returned or raised
by the __missing__(key) call [2].

And in defaultdict.__missing__() calling default factory raises an exception
this should be propagated unchanged[3].

So d[key] operation on a defaultdict should get whatever default factory raises.

----

[1] https://docs.python.org/2/library/collections.html#collections.defaultdict

... It overrides one method and adds one writable instance variable.
The remaining functionality is the same as for the dict class and is
not documented here.

[2] https://docs.python.org/2/library/stdtypes.html#dict

... The d[key] operation then returns or raises whatever is returned or
raised by the __missing__(key) call.

[3] https://docs.python.org/2/library/collections.html#collections.defaultdict.__missing__

... If calling default_factory raises an exception this exception
is propagated unchanged.
History
Date User Action Args
2016-09-25 19:56:31buelgsk8ersetrecipients: + buelgsk8er
2016-09-25 19:56:31buelgsk8ersetmessageid: <1474833391.39.0.543279624299.issue2523@psf.upfronthosting.co.za>
2016-09-25 19:56:31buelgsk8erlinkissue2523 messages
2016-09-25 19:56:30buelgsk8ercreate