-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
reflect pydantic's type leniency #36
Comments
I often think about the situation. I agree. It's stupid to implement the same logic in kotlin. I have an idea. The plugin may have a type support list for famous types. example: Also, I guess build script can generate the support list by python.
The plugin doesn't know to obtain what value when run. |
Friendly/more correct message is definitely the best first step. |
I personally would prefer it say something, even if parsing would succeed. Maybe this could be a plug-in option? (If the point is just to change the warning message then that’s fine with me.) |
is there any option in pycharm for some kind of "weak warning"? That would be optimal. |
I guess we need to create a new configuration panel for the plugin. |
Yes, I'd be fine having it drop to weak warning. My mypy plugin already has configurable strictness, I think, so I'm happy to rely on that beyond weak warnings (though I don't know whether it would be easy or even possible to have a configurable set of "allowed casts" in mypy -- right now, non-strict just means mypy sees a type-hint of I wouldn't be surprised if people wanted to disable the warning entirely though, so I'm still in favor of configurability of the plugin/inspection. Maybe it would be easier if it were possible to just enable/disable the inspection? I wouldn't care what the default value was -- I'd be happy to manually set it however I wanted it.) |
@samuelcolvin
This feature is disabled in default. Also, I write how to use the inspection in document pages, and the link is in PyCharm settings. https://koxudaxi.github.io/pydantic-pycharm-plugin/type-checking/ [tool.pydantic-pycharm-plugin]
# You can select highlight level from "warning", "weak_warning", "disable"
parsable-type-highlight = "warning"
acceptable-type-highlight = "weak_warning"
[tool.pydantic-pycharm-plugin.parsable-types]
## datetime.datetime field may parse int
"datetime.datetime" = ["int"]
[tool.pydantic-pycharm-plugin.acceptable-types]
# str field accepts to parse int and float
str = ["int", "float"] |
That's cool. Could you look at the equivalent mypy flag and use that? |
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'll duplicate this to the pydantic repo when I'm back at my desk. |
Did you talk about
I agree.
Thank you very much. |
pydantic has lots of support for coercing types, however pydantic-pycharm-plugin current gives a message saying simply
Expected type "x", got "y" instead
: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
orstr
when the field is of typedatetime
? 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 forint
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!The text was updated successfully, but these errors were encountered: