Custom Fields not recognised by PyCharm
See original GitHub issueI have the following custom Field:
class NonEmptyString(str):
@classmethod
def __get_validators__(cls):
yield cls.validate
@classmethod
def validate(cls, v):
if v == "":
raise ValueError("Non-empty string expected")
return v
and a model using it:
class MyModel(BaseModel):
field: NonEmptyString
but when I instantiate MyModel
:
my_model = MyModel(field="a string")
I get the following warning from pycharm’s linter:
Expected type 'NonEmptyString' got 'str' instead
Is this behaviour expected?
Versions
pydantic 1.1.1
pycharm-pydantic-plugin: 0.0.27
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
YouTrack Server - Create and Edit Custom Fields - JetBrains
From the Administration menu, select Custom Fields. · Select the Fields List tab. · Select the field in the list. · Edit the...
Read more >Configure a Python interpreter | PyCharm Documentation
The Python interpreter name specified in the Name field, becomes visible in the list of available interpreters. Click OK to apply the changes....
Read more >Type hinting in PyCharm - JetBrains
PyCharm supports type hinting in function annotations and type comments using the typing module and the format defined by PEP 484.
Read more >Hiding custom fields + figuring out how to populate other fields ...
If you haven't attached the "Subsytem" yet you have to go to the project "Field tab", click "Attach Field", select "Subsystem", select " ......
Read more >Disabling and enabling inspections | PyCharm Documentation
Re-enable inspections · In the Settings/Preferences dialog ( Ctrl+Alt+S ), select to Editor | Inspections. You can also press Ctrl+Alt+Shift+H and select ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
FYI, pydantic
EmailStr
has a bug.EmailStr
type is used in a model,the plugin raises a warning on editor.
This code is type checking safe, but running it on Linux raises ValidationError. https://github.com/samuelcolvin/pydantic/issues/1070#issuecomment-568477871
@avlahop
Yes, We expect the behavior. @dmontagu explained about the behavior and history.
We should add a panel of settings to control the warnings. Sorry, I have not tried to implement the feature yet. I will try it next week.
@dmontagu Your idea looks good. But I try to implement the panel of settings. If I can not do it next week, then let’s discuss the option on `config.