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

add default (de)serializer for Literal values #180

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

Conversation

buckley-w-david
Copy link

@buckley-w-david buckley-w-david commented Jul 4, 2022

I implemented these for a project I'm working on that uses jsons, then noticed #170 and figured I may as well see if you like the implementation enough to go with it.

I included the strictly_equal_literal as a compromise between correctness and utility.

From https://peps.python.org/pep-0586/#equivalence-of-two-literals

Two types Literal[v1] and Literal[v2] are equivalent when both of the following conditions are true:

  1. type(v1) == type(v2)
  2. v1 == v2

I took that to mean that for a value to really match a literal it should match in both type and value. The only problem with that is that I've found it to be very useful to allow jsons to "coerce" values that are equal in value into the literal value, the use case that prompted me to implement this actually relies on that behaviour.

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.

1 participant