diffplug / diffplug/selfie

[py] consequences of allowing snapshots based on repr

Open
#516 0 comments 0 reactions 0 assignees View on GitHub
py
Dominant language
Kotlin
Stars
101
Forks
18
PR merge metrics
No merged PRs in 30d

Description

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](https://github.com/user-attachments/assets/fc57d9b7-2d79-439b-bd73-650548bab8b0)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.