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 support for Literal annotation #582

Merged
merged 11 commits into from Jun 25, 2019
Merged

Conversation

dmontagu
Copy link
Contributor

@dmontagu dmontagu commented Jun 7, 2019

Change Summary

Properly handle attributes annotated with typing_extensions.Literal


If you like this, let me know and I'll add documentation and finish the other bullets in the checklist. I'd also be happy to try implementing a workaround to eliminate the typing_extensions dependency (given some guidance about the desired outcome). I could also look into how to better integrate with the schema.

If you don't like this (e.g., because you think my implementation is awkward, or because you think this feature is just premature while Literal remains in typing_extensions rather than typing), no worries -- I'll just close the pull request and maybe come back to it at a later date. But the implementation seemed simple enough that I felt like it was worth sharing.

Related issue number

#561

Checklist

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • HISTORY.rst has been updated
    • if this is the first change since a release, please add a new section
    • include the issue number or this pull request number #<number>
    • include your github username @<whomever>

Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm keen on the idea, just a few things to fix.

pydantic/fields.py Outdated Show resolved Hide resolved
pydantic/errors.py Outdated Show resolved Hide resolved
pydantic/validators.py Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Jun 12, 2019

Codecov Report

Merging #582 into master will not change coverage.
The diff coverage is 100%.

@@          Coverage Diff          @@
##           master   #582   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          15     15           
  Lines        2582   2613   +31     
  Branches      510    516    +6     
=====================================
+ Hits         2582   2613   +31

Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also need to:

  • add this to docs
  • update travis to run with and without typing_extensions, same as it currently does for ujson etc.

Otherwise this is looking great.

pydantic/fields.py Show resolved Hide resolved
pydantic/utils.py Outdated Show resolved Hide resolved
pydantic/utils.py Outdated Show resolved Hide resolved
pydantic/fields.py Outdated Show resolved Hide resolved
pydantic/errors.py Outdated Show resolved Hide resolved
pydantic/validators.py Outdated Show resolved Hide resolved
setup.py Outdated Show resolved Hide resolved
pydantic/errors.py Outdated Show resolved Hide resolved
pydantic/fields.py Outdated Show resolved Hide resolved
pydantic/utils.py Outdated Show resolved Hide resolved
pydantic/validators.py Show resolved Hide resolved
setup.py Outdated Show resolved Hide resolved
setup.py Show resolved Hide resolved
pydantic/validators.py Outdated Show resolved Hide resolved
pydantic/validators.py Outdated Show resolved Hide resolved
Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, just a few small things then please add to history and docs.

I'm confused about why the coverage appears to have dropped, maybe that is just codecov getting confused.

pydantic/errors.py Outdated Show resolved Hide resolved
pydantic/errors.py Outdated Show resolved Hide resolved
pydantic/validators.py Outdated Show resolved Hide resolved
setup.py Show resolved Hide resolved
.travis.yml Outdated Show resolved Hide resolved
@lgtm-com
Copy link

lgtm-com bot commented Jun 23, 2019

This pull request introduces 2 alerts when merging c5ac4e7 into 461b852 - view on LGTM.com

new alerts:

  • 2 for Module-level cyclic import

@lgtm-com
Copy link

lgtm-com bot commented Jun 23, 2019

This pull request introduces 1 alert when merging 9a3cd2d into 461b852 - view on LGTM.com

new alerts:

  • 1 for Module-level cyclic import

@dmontagu
Copy link
Contributor Author

dmontagu commented Jun 25, 2019

@samuelcolvin thanks for merging this, I'll add docs soon

@samuelcolvin
Copy link
Member

great thanks, somehow forgot about that.

@jasonkuhrt
Copy link

Great job all!

alexdrydew pushed a commit to alexdrydew/pydantic that referenced this pull request Dec 23, 2023
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.

None yet

3 participants