Skip to content

Add missing repr for mappingproxy - #3197

Merged
DimitrisJim merged 2 commits into
RustPython:mainfrom
Snowapril:mapping_proxy_repr
Oct 2, 2021
Merged

DimitrisJim merged 2 commits into
RustPython:mainfrom
Snowapril:mapping_proxy_repr

Conversation

@Snowapril

@Snowapril Snowapril commented Oct 2, 2021 •

Copy link
Copy Markdown
Contributor

This revision implements repr method of mappingproxy type.

There are two case of repr in mapping proxy.

cpython

>>> mappingproxy = type(type.__dict__)
>>> mappingproxy({"ASCII": 256})
mappingproxy({'ASCII': 256})
>>> int.__dict__
mappingproxy({'__repr__': <slot wrapper '__repr__' of 'int' objects>, '__hash__': <slot wrapper '__hash__' of 'int' 
objects>, '__getattribute__': <slot wrapper '__getattribute__' of 'int' objects>, '__lt__': <slot wrapper '__lt__' of 'int' objects>, '__le__': 
<slot wrapper '__le__' of 'int' objects>, '__eq__':  .........(skip).......... })

But original rustpython just print <mappingproxy object at 0x55dc213e7eb0>.
With this fix, rustpython also print like cpython.

rustpython

>>>>> mappingproxy = type(type.__dict__)
>>>>> mappingproxy({"ASCII":256})
mappingproxy({'ASCII': 256})
>>>>> int.__dict__
mappingproxy({'conjugate': <method 'conjugate' of 'int' objects>, '__format__': <method '__format__' of 'int' objects>, '__lshift__': 
<method '__lshift__' of 'int' objects>, '__mod__': <method '__mod__' of 'int' objects>, ............(skip).............. })

In addition, test_field_repr in test_dataclasses.py and test_mapping_proxy & test_sort_orderable_and_unorderable_values in test_pprint.py now go works

Signed-off-by: snowapril <sinjihng@gmail.com>
Signed-off-by: snowapril <sinjihng@gmail.com>
@DimitrisJim
DimitrisJim merged commit c991dff into RustPython:main Oct 2, 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.

3 participants