pydantic-pycharm-plugin: Autoimport breaks when enabling the plugin

Describe the bug Having the pydantic-pycharm-plugin enabled breaks autoimports.

To Reproduce Steps to reproduce the behavior:

  1. Install the pydantic plugin and enable it
  2. Create a simple file main.py with the content:
from typing import Optional
from pydantic import BaseModel


class Item(BaseModel):
    name: str
    description: Optional[str] = Field()
    price: float
    tax: Optional[float] = None
  1. Navigate the caret between Field and ().
  2. ctrl+space+space or alt+enter
  3. No pydantic import suggested

bilde
bilde

  1. Disable pydantic plugin
  2. Try the same:

bilde
bilde

Expected behavior Autoimports should work.

Environments (please complete the following information):

  • IDE: PyCharm Professional 2021.1 (Edit: Tested in 201.1.1 as well. Same issue)
  • OS: Red Hat Enterprise Linux release 8.3 (Ootpa)
  • Pydantic Versio: 1.8.1
  • Plugin version: 0.3.0

Additional context I’ve tried recreating the environment, clearing and invalidating cache.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 21 (8 by maintainers)

Most upvoted comments

I’ll check out both pipx and your poetry plugin, thank you!!

Also, You are sponsoring me!!

I listened to episode 313 of talkpython.fm. Creator of pydantic gave you some nice words and in the end of the episode he encourages not only sponsoring the huge packages, but also those who make those packages awesome. This is one of them. 😊 So my pleasure.

Screenshot_from_2021-04-28_16-51-19

Tried on Ubuntu 20.04.2 with Pycharm: 2021.1

Same to you 😸

Did you open the same project?

No, this time it was a personal project.
I’ll try a fresh project with nothing but pydantic installed tomorrow - with and without a virtual environment.

I can think of only the part. If the plugin affects the problem.

Are other functions and classes suggested? (exp: BaseModel, validator)

I don’t think so, I’ll confirm tomorrow.

Did you know other differences to other distribution?

But, PyCharm run on JVM. I guess the differences may not relate to this problem.

I’m using bundled Java. They are on Windows and on Mac, using same version of the plugin and Pycharm. So, it seems to work for everyone but me.

Don’t know what more information I could add about my environment except that I’m using Wayland and Swaywm. Installed using toolbox.
I could try to do a manual install of the 2020.x version?

Sorry, never got the chance to do this. I’ll try tomorrow.

I will test first thing tomorrow morning. I’m unfortunately out for the day.

Thank you for the quick follow up!

I talked to multiple in the FastAPI discord who said it worked perfectly fine for them as well, so I’m not sure what to do.

I tried disabling all plugins except this one, in case there was some interfering plugins causing the issue, but same issue.

Let me know if there is some logs or something I can test for you.