Skip to content

Fix PyMappingProxy::get - #2994

Merged
youknowone merged 2 commits into
RustPython:mainfrom
moreal:bugfix/fix-mappingproxy-get
Aug 31, 2021
Merged

youknowone merged 2 commits into
RustPython:mainfrom
moreal:bugfix/fix-mappingproxy-get

Conversation

@moreal

@moreal moreal commented Aug 31, 2021 •

Copy link
Copy Markdown
Contributor

Overview

When we run the Python code like below:

class A: ...

print(A.__dict__.items())
print(A.__dict__.get("__hash__", "NONE"))

We can't find __hash__ anywhere and will see NONE output because there is no __hash__ method.

Let's see the output from the execution result of CPython implementation.

dict_items([('__module__', '__main__'), ('__dict__', <attribute '__dict__' of 'A' objects>), ('__weakref__', <attribute '__weakref__' of 'A' objects>), ('__doc__', None)])
NONE

But RustPython implementation fetches the object.__hash__ method though it doesn't have.

dict_items([('__dict__', <getset_descriptor object at 0x556b113c8460>), ('__module__', '__main__'), ('__qualname__', 'A'), ('__doc__', None)])
<method '__hash__' of 'object' objects>

So this pull request fixed the bug, similar with #2932.

@youknowone youknowone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch!

@youknowone
youknowone merged commit 27f187e into RustPython:main Aug 31, 2021
@youknowone youknowone added the z-ca-2021 Tag to track contrubution-academy 2021 label Oct 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

z-ca-2021 Tag to track contrubution-academy 2021

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants