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 more information to resolved TypedDicts #654

Merged

Conversation

JoshFerge
Copy link
Contributor

@JoshFerge JoshFerge commented Feb 12, 2022

  • on py 3.9 and above, use the __required_keys__ field to annotate TypedDict values with required keys
  • Add a description via the hint's __doc__ attribute if it exists

This would be a breaking change resulting in different OpenAPI schema if end-users didn't mark their TypedDicts with total=False on 3.9 and above, as previously, all TypedDict fields were optional.

@codecov
Copy link

codecov bot commented Feb 12, 2022

Codecov Report

Merging #654 (7da9abf) into master (27ac1ca) will decrease coverage by 0.39%.
The diff coverage is 38.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #654      +/-   ##
==========================================
- Coverage   98.80%   98.40%   -0.40%     
==========================================
  Files          63       63              
  Lines        7005     6767     -238     
==========================================
- Hits         6921     6659     -262     
- Misses         84      108      +24     
Impacted Files Coverage Δ
tests/test_plumbing.py 88.13% <16.66%> (-11.87%) ⬇️
drf_spectacular/plumbing.py 96.43% <83.33%> (-1.15%) ⬇️
drf_spectacular/helpers.py 83.33% <0.00%> (-1.67%) ⬇️
drf_spectacular/drainage.py 97.67% <0.00%> (-1.21%) ⬇️
drf_spectacular/checks.py 77.77% <0.00%> (-1.17%) ⬇️
tests/test_fields.py 99.45% <0.00%> (-0.55%) ⬇️
drf_spectacular/contrib/rest_auth.py 94.59% <0.00%> (-0.35%) ⬇️
tests/conftest.py 97.72% <0.00%> (-0.15%) ⬇️
... and 34 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 27ac1ca...7da9abf. Read the comment docs.

Copy link
Owner

@tfranzel tfranzel left a comment

Choose a reason for hiding this comment

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

Hey @JoshFerge, thanks for the PR. excellent stuff!

the breakage is fine i think because it's the correct thing to do. i suppose it would have broken anyway if someone would have used the constructor init with missing arguments (TD1(**data)), right?

LGTM with the doc retrieval change

drf_spectacular/plumbing.py Outdated Show resolved Hide resolved
@JoshFerge
Copy link
Contributor Author

Hey @JoshFerge, thanks for the PR. excellent stuff!

the breakage is fine i think because it's the correct thing to do. i suppose it would have broken anyway if someone would have used the constructor init with missing arguments (TD1(**data)), right?

LGTM with the doc retrieval change

Yep, exactly


required = None

if sys.version_info >= (3, 9):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i'm going to do some quick testing sometime this week to see if it just works with the typing_extension TypedDict as well (what we're using since we're not on 3.9 yet), in which case we can simply check the hint for the __required_keys__ attribute.

tfranzel added a commit that referenced this pull request Feb 15, 2022
@tfranzel tfranzel merged commit 7da9abf into tfranzel:master Feb 15, 2022
@tfranzel
Copy link
Owner

Hey, I fixed the call and found a issue with this new case in getdoc. fixed it and merged the PR. let me know if this works for you.

@JoshFerge
Copy link
Contributor Author

JoshFerge commented Feb 15, 2022

Hey, I fixed the call and found a issue with this new case in getdoc. fixed it and merged the PR. let me know if this works for you.

Yup! Thanks!

tfranzel added a commit that referenced this pull request Nov 17, 2022
Also use feature detection for __required_keys__ instead of
probing Py version
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

2 participants