3 ms·
cool library. although worth keeping in mind that strong typing doesn't solve all your problems. here's an example, taking the second example on this page http
by a-dub 3y ago
cool library. although worth keeping in mind that strong typing doesn't solve all your problems.
here's an example, taking the second example on this page https://docs.pydantic.dev/latest/ https://docs.pydantic.dev/latest/ with the external_data dictionary, if i add a collision like:
'wine': 9,
'wine': 1,
it seems to just silently pick the last one, which seems error prone to me. maybe there's a flag to fix it, but i couldn't find any documentation or switches that controlled this behavior. :/
with respect to the approach i mentioned above, it's more of an idea (or probably a research topic) to do quantitative analysis on the behavior of programs while they execute, rather than static analysis of the code that defines them. the latter is obviously preferable, assuming the approach can capture all of the types of analyses of interest, the quantitative approach may be more suitable for large or legacy systems where detecting changes in data shape (even if of valid type) and branching behavior may be useful for tracking down causes of, or detecting conditions for, errant behaviors.
- MrJohz 3y agoPydantic operates on Python dictionaries, so questions about duplicate keys will come down to whatever the Python behaviour is. (I.e. if you have a dictionary literal with duplicate keys, Python will select which key "wins" before Pydantic gets a chance to intervene.) When loading directly from JSON, it's possible to hook into Python's JSON-parsing mechanism and throw on duplicate keys, which probably ought to be the default given the number of security risks that come from this case.