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.

Custom Fields not recognised by PyCharm

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
otsukacommented, Dec 24, 2019

FYI, pydantic EmailStr has a bug.

EmailStr type is used in a model,

addr = Address(email='foo@example.com')

the plugin raises a warning on editor.

addr = Address(email=EmailStr('foo@example.com'))

This code is type checking safe, but running it on Linux raises ValidationError. https://github.com/samuelcolvin/pydantic/issues/1070#issuecomment-568477871

1reaction
koxudaxicommented, Nov 23, 2019

@avlahop

Is this behaviour expected?

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.

Read more comments on GitHub >

github_iconTop 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 >

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