Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silenced error in __getitem__ when compare with a mapping #460

Closed
serhiy-storchaka opened this issue Feb 9, 2020 · 0 comments · Fixed by #461
Closed

Silenced error in __getitem__ when compare with a mapping #460

serhiy-storchaka opened this issue Feb 9, 2020 · 0 comments · Fixed by #461

Comments

@serhiy-storchaka
Copy link
Contributor

The following code

from multidict import MultiDict
from collections.abc import Mapping

class BadMapping(Mapping):
    def __getitem__(self, key):
        1 / 0
    def __iter__(self):
        yield "a"
    def __len__(self):
        return 1

print(MultiDict(a=1) == BadMapping())

silences the exception and prints

False

This can cause returning wrong result when evaluation of __getitem__ was interrupted by an unexpected error like KeyboardInterrupt or MemoryError.

@helpr helpr bot added the pr-available label Feb 9, 2020
@helpr helpr bot added pr-merged and removed pr-available labels Feb 12, 2020
buildroot-auto-update pushed a commit to buildroot/buildroot that referenced this issue Mar 2, 2020
Bugfix release, fixing a number of issues. From the CHANGES file:

- Fixed creating and updating of MultiDict from a sequence of pairs and
  keyword arguments.  Previously passing a list argument modified it
  inplace, and other sequences caused an error.
  aio-libs/multidict#457

- Fixed comparing with mapping: an exception raised in the __len__ method caused raising a SyntaxError.
  aio-libs/multidict#459

- Fixed comparing with mapping: all exceptions raised in the __getitem__
  method were silenced.
  aio-libs/multidict#460>

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
[Peter: extend commit message]
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant