Skip to content

add default (de)serializer for Literal values - #180

Open
buckley-w-david wants to merge 2 commits into
ramonhagenaars:masterfrom
buckley-w-david:master
Open

add default (de)serializer for Literal values#180
buckley-w-david wants to merge 2 commits into
ramonhagenaars:masterfrom
buckley-w-david:master

Conversation

@buckley-w-david

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

Copy link
Copy Markdown

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