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

fix coverage and make typing-extensions a required dependency #2368

Merged
merged 10 commits into from Feb 17, 2021

Conversation

samuelcolvin
Copy link
Member

fix #2367

@codecov
Copy link

codecov bot commented Feb 15, 2021

Codecov Report

Merging #2368 (f500367) into master (fc18f8e) will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           master     #2368      +/-   ##
===========================================
+ Coverage   99.97%   100.00%   +0.02%     
===========================================
  Files          23        23              
  Lines        4500      4485      -15     
  Branches      909       909              
===========================================
- Hits         4499      4485      -14     
+ Misses          1         0       -1     
Impacted Files Coverage Δ
pydantic/annotated_types.py 100.00% <100.00%> (ø)
pydantic/fields.py 100.00% <100.00%> (ø)
pydantic/schema.py 100.00% <100.00%> (ø)
pydantic/typing.py 100.00% <100.00%> (+0.57%) ⬆️
pydantic/validators.py 100.00% <100.00%> (ø)

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 fc18f8e...6b2bcfc. Read the comment docs.

@samuelcolvin samuelcolvin marked this pull request as ready for review February 15, 2021 13:20
@antdking
Copy link
Contributor

Do you think it's worth changing to depending on typing-extensions>=3.7.4.3 going forward?
That should remove the need for all the custom implementations of get_args, and guarantees availability of Annotated.

I'm unsure if anyone's raised it, but could also prevent issues with type checkers who don't use typing-extensions (Pyright comes to mind here, but I'd have to check if it's an actual issue or not).

Copy link
Member

@PrettyWood PrettyWood left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for fixing this

@@ -7,8 +7,9 @@
from pydantic.fields import Undefined
from pydantic.typing import Annotated

pytestmark = pytest.mark.skipif(not Annotated, reason='typing_extensions not installed')
Copy link
Member

Choose a reason for hiding this comment

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

👍

@samuelcolvin
Copy link
Member Author

This is a change to the Annotated solution implemented in #2147, @JacobHayes are you happy with it?

Do you think it's worth changing to depending on typing-extensions>=3.7.4.3 going forward?

I think that's a good idea @JacobHayes suggested it on the original PR, I'll see how easy this would be now.

Copy link
Contributor

@JacobHayes JacobHayes left a comment

Choose a reason for hiding this comment

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

PR LGTM! The world is probably a better place without _FalseMeta 😁

Do you think it's worth changing to depending on typing-extensions>=3.7.4.3 going forward?
That should remove the need for all the custom implementations of get_args, and guarantees availability of Annotated.

It's probably a net benefit, but there were a few caveats to making things very clean:

I was able to refactor the get_args/get_origin stuff a bit with typing_extensions, but it's not a panacea:

  • those helper funcs aren't available on 3.6 so I kept the old "polyfills"
  • I had to remove two tests using a bare Callable (the typing_extensions functions seem to expect the Callable generics to be [...]). Might get just as messy again to add the shim if those are truly valid cases (creating a Model with a bare Callable field hint seemed to still work)
  • Looks like this makes the "test compiled without deps" fail (since we now import typing_extensions). Does this need to be tweaked somehow?

It might be pretty tidy after dropping py 3.6 though, I think(?) the other two are more minor. Looks like @samuelcolvin whipped that up pretty quick. 👍

@samuelcolvin samuelcolvin changed the title fixing coverage by simplifying Annotated import logic fix coverage and make typing-extensions a required dependency Feb 17, 2021
@samuelcolvin
Copy link
Member Author

Looks ready. @PrettyWood are you happy with this?

I ❤️ negative PRs 😍.

'Fields will therefore be considered all required or all optional depending on class totality.',
UserWarning,
if not hasattr(typeddict_cls, '__required_keys__'):
raise TypeError(
Copy link
Contributor

Choose a reason for hiding this comment

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

This change should probably be explicitly noted as a breaking change in the changelog, just in case there are people ignoring the warning.

I can also think of scenarios where people are using another libraries TypedDict, but I'm not sure if that's common or not (I've never done this before).

Copy link
Member

Choose a reason for hiding this comment

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

No need it's in the same new version v1.8 ;)

@PrettyWood
Copy link
Member

@samuelcolvin We could maybe update docs/examples/schema_annotated.py but up to you.
Looks great!

Copy link
Contributor

@antdking antdking left a comment

Choose a reason for hiding this comment

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

Nice work. I didn't realise that typing-extensions didn't backport get_args for py36, so future trimmings to come

Copy link
Contributor

@JacobHayes JacobHayes left a comment

Choose a reason for hiding this comment

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

Very nice cleanup!


# Annotated[...] is implemented by returning an instance of one of these classes, depending on
# python/typing_extensions version.
AnnotatedTypeNames = {'AnnotatedMeta', '_AnnotatedAlias'}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be moved up since it's referenced in the branches above?

@samuelcolvin
Copy link
Member Author

It might be pretty tidy after dropping py 3.6 though, I think(?) the other two are more minor.

#2374

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.

Put back coverage at 100%
4 participants