question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

reflect pydantic's type leniency

See original GitHub issue

pydantic has lots of support for coercing types, however pydantic-pycharm-plugin current gives a message saying simply Expected type "x", got "y" instead:

image

Is there any possibility to change the error message to something like Field is of type "x", "y" may not be parsable to "x"? (or something cleaner, can’t think right now)

Perhaps it might even be possible to not show a warning in some obvious cases eg, int or str when the field is of type datetime? If that’s not possible, just making the message more friendly/correct might be simplest.

I can imagine that actually trying to parse the value and see if it’ll work (eg. '1' will work for int but 'x' would not) would involve duplicating the whole of pydantic’s logic in kotlin which is completely impossible. So I’m definitely not asking for that!

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:5
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
samuelcolvincommented, Aug 15, 2019

Friendly/more correct message is definitely the best first step.

0reactions
koxudaxicommented, Apr 23, 2020

@samuelcolvin

That’s cool. Could you look at the equivalent mypy flag and use that?

Did you talk about init_typed and warn_untyped_fields_check_box ? If I can parse ini file in Java/Kotlin, then I can do it.

I think we should build a master copy of what types pydantic can accept as inputs to what types, e.g.: I see this information being useful in a number of scenarios:

I agree. It’s a great idea 😄

I’ll duplicate this to the pydantic repo when I’m back at my desk.

Thank you very much.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Postponed annotations - pydantic
To resolve strings (type names) into annotations (types), pydantic needs a namespace dict in which to perform the lookup.
Read more >
pydantic [python-library] - Occam :: Details
Data validation and settings management using Python type hinting. Fast and extensible, pydantic plays nicely with your linters/IDE/brain. Define how data ...
Read more >
Cool Things You Can Do With Pydantic - Medium
Pydantic models. Pydantic is a useful library for data parsing and validation. It coerces input types to the declared type (using type ......
Read more >
Field Types - pydantic
Where possible pydantic uses standard library types to define fields, thus smoothing the ... However, it may not reflect the desired behavior; see...
Read more >
How To Get Pydantic To Discriminate On A Field Within List ...
So far, I have written the following Pydantic models listed below, to try and reflect this. The Rest API json payload is using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found