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

LazilyUnpickling{Dict,List}: add __repr__ #817

Merged
merged 2 commits into from
Nov 14, 2024
Merged

Conversation

matthiasdiener
Copy link
Collaborator

@matthiasdiener matthiasdiener commented Nov 20, 2023

from loopy.tools import LazilyUnpicklingList, LazilyUnpicklingDict, _PickledObject
l = LazilyUnpicklingList([1, 2, 3, 4])
print(l)
d = LazilyUnpicklingDict({'a':1, 'b':2})
print(d)
p = _PickledObject(7)
print(p)

before:

<loopy.tools.LazilyUnpicklingList object at 0x101810810>
<loopy.tools.LazilyUnpicklingDict object at 0x104b2ccd0>
<loopy.tools._PickledObject object at 0x10103a450>

after:

LazilyUnpicklingList([1, 2, 3, 4])
LazilyUnpicklingDict({'a': 1, 'b': 2})
_PickledObject(7)

(If you want, I could add __str__ methods that don't include the class names.)

@matthiasdiener matthiasdiener self-assigned this Nov 20, 2023
@matthiasdiener matthiasdiener changed the title LazilyUnpickling{Dict,List}: better repr LazilyUnpickling{Dict,List}: add __repr__ Dec 1, 2023
@matthiasdiener
Copy link
Collaborator Author

This is ready for review.

loopy/tools.py Outdated
@@ -411,6 +411,9 @@ def unpickle(self):
def __getstate__(self):
return {"objstring": self.objstring}

def __repr__(self) -> str:
return repr(self.unpickle())
Copy link
Owner

Choose a reason for hiding this comment

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

This hides the _PickledObject layer... is that wise?

Copy link
Collaborator Author

@matthiasdiener matthiasdiener Dec 8, 2023

Choose a reason for hiding this comment

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

What do you think of 8c13355 ac81ec7?

@inducer inducer force-pushed the repr-lazilydictlist branch from 9be8be2 to 9ff0285 Compare November 14, 2024 15:26
@inducer inducer enabled auto-merge (squash) November 14, 2024 15:26
@inducer inducer merged commit 41b3288 into main Nov 14, 2024
18 checks passed
@inducer inducer deleted the repr-lazilydictlist branch November 14, 2024 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants