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

[py] consequences of allowing snapshots based on repr #516

Open
nedtwigg opened this issue Feb 19, 2025 · 0 comments
Open

[py] consequences of allowing snapshots based on repr #516

nedtwigg opened this issue Feb 19, 2025 · 0 comments
Labels

Comments

@nedtwigg
Copy link
Member

Python has a very cool repr() method, which returns the source code required to create the object. Not everything implements it, but Python's core datastructures do.

For inline snapshots it's pretty easy - we call repr() on argument, and put that inside the to_be() call.

For disk snapshots, we would have to read the value from the snapshot, call eval() on that string, and then hope that the comparison logic is implemented correctly.

In both cases, it muddies the concept of equality a bit, but allowing repr is so convenient that it's worth it.

Image

@nedtwigg nedtwigg added the py label Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant