-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Properly retain types of Mapping subclasses #2325
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2325 +/- ##
==========================================
- Coverage 99.90% 99.76% -0.14%
==========================================
Files 25 25
Lines 5039 5062 +23
Branches 1031 1037 +6
==========================================
+ Hits 5034 5050 +16
- Misses 1 5 +4
- Partials 4 7 +3
Continue to review full report at Codecov.
|
Co-Authored-By: Eric Jolibois <[email protected]>
@PrettyWood I'm not sure how to fix the type checking errors |
Co-Authored-By: Eric Jolibois <[email protected]>
@PrettyWood The current job failure is due to https://pypi.org/project/cryptography/3.4.1/ emitting a warning in the test suite of FastAPI |
Yep can't do anything about that now but it should be handled rapidly on FastAPI side. |
Done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ofek We should still check the set type and try to coerce when needed.
For example
class M(BaseModel):
x: Dict[str, int]
should coerce to dict
. Right now there is no difference between Dict
and Mapping
...
I updated https://github.com/PrettyWood/pydantic/pull/70/files if you want
Note that I think we should probably have a proper validator for Dict
(at least) before Mapping
to avoid any performance impact on normal dictionaries (like it's done for Tuple
or List
, which are treated before Sequence
)
Updated based on your branch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still reckon we should at least have SHAPE_DICT
(extra could be SHAPE_DEFAULTDICT
, SHAPE_COUNTER
...) before SHAPE_MAPPING
to have no perf impact.
Or at least if we go with it we should have a benchmark to see the impact
@PrettyWood Addressed. I'm not familiar with the concept of shapes here. Can you explain? |
@ofek pydantic is fast because a lot is done in the metaclass. You can have a look at |
I just tried that but many tests are failing now |
should I revert the last commit for now? |
I'm still trying but I don't understand what's wrong 🙁 |
@PrettyWood Could you please take a look when you get a chance? |
I'll have a look tonight or tomorrow 👍 |
Thank you, feel free to push directly to my branch! |
Hi @ofek |
Co-Authored-By: Eric Jolibois <[email protected]>
@PrettyWood Done! Added that test too |
I let @samuelcolvin have a look. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
otherwise this is looking good.
@samuelcolvin Thanks, addressed! |
Done this look alright now? |
@samuelcolvin Just let me know if I have to do anything else! FYI, after this is merged and released, every Datadog Agent integration will exclusively use pydantic for user configuration 🙂 |
This is great. Thank you.
I don't see pydantic as a dependency, what am I missing? |
DataDog/integrations-core#8675 is merged and I've started the syncing of every integration: https://github.com/DataDog/integrations-core/pulls 😄 |
Change Summary
This change prevents Mapping subclasses from always being coerced to
dict
Related issue number
Resolves #2323
closes #1536
Checklist
changes/<pull request or issue id>-<github username>.md
file added describing change(see changes/README.md for details)