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

Non to-string version on dataclasses #160

Open
C0DK opened this issue Mar 11, 2021 · 0 comments
Open

Non to-string version on dataclasses #160

C0DK opened this issue Mar 11, 2021 · 0 comments

Comments

@C0DK
Copy link

C0DK commented Mar 11, 2021

When utilizing dataclasses you can define them to be identified by it's attributes. It'd be nice if rather than doing the "GeneralRepr" solution, you would simply use the dir(obj) when making a snapshot of a given dataclass, rather than simply using the __repr__ version. It also makes it a whole lot more difficult to check the diffs when looking at two lists of dataclasses.

In general i wish your lovely module had some custom way of doing the snapshot representation of a given class, if predefined.

i.e a config where you could create a function like:

def to_snapshot(obj: object):
  if isinstance(obj, Person):
    return {obj.name, obj.age}
  return super().to_snapshot

Something..

So it'd be possible to improve the snapshots a bit without having to do a whole lot of bootstrapping for each individual test and/or override __repr__ to return a non-string, which i think is bad practice.

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

No branches or pull requests

1 participant