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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

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

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?

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.

None yet

2 participants