Skip to content
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

ClassVar fields are ignored / not recognized #187

Closed
skewty opened this issue Sep 4, 2020 · 4 comments
Closed

ClassVar fields are ignored / not recognized #187

skewty opened this issue Sep 4, 2020 · 4 comments
Labels
enhancement New feature or request released

Comments

@skewty
Copy link

skewty commented Sep 4, 2020

Describe the bug
When creating a model that has a field type hinted with "typing.ClassVar", it is ignored / not recognized.

To Reproduce

from typing import ClassVar
from pydantic import BaseModel

class FooModel(BaseModel):
    special_name_a: ClassVar[str] = 'CEO'
    _special_name_b = 'CFO'
    __special_name_c__ = 'Janitor'

    name: str

FooModel.|   # cursor at the pipe
# PyCharm does not show existence of `special_name_a` field.
# PyCharm does not show existence of `_special_name_b` field.
# PyCharm does show existence of `__special_name_c__` field.
# Pydantic recognizes the type hint and does not make a model field named 'special_name_a'.
# Pydantic recognizes the leading underscore and does not make a model field named '_special_name_b'.
# Pydantic recognizes the leading and trailing underscores and does not make a model field named '__special_name_c__'.

Expected behavior
I expect PyCharm (the plug-in) to recognize the class level fields. Both 'special_name_a' and 'special_name_c' should be presented in auto-complete. I don't expect the "protected" field of _special_name_b to show up but PyCharm should be made aware of it so people who want to show protected fields will also see it.

You already recognize the magics (__magic__) as class level. You should be able to make use of that code.

Environments (please complete the following information):

  • IDE: PyCharm Pro 2020.2.1
  • OS: PopOS 20.04
  • Pydantic Version 1.4
  • Plugin version 0.1.11
@koxudaxi
Copy link
Owner

koxudaxi commented Sep 6, 2020

@skewty
Thank you for creating this issue.
I have confirmed the problem.
I will fix it.

@koxudaxi koxudaxi added the enhancement New feature or request label Sep 6, 2020
@koxudaxi
Copy link
Owner

koxudaxi commented Sep 7, 2020

@skewty
I have released a new version as 0.1.13.

@skewty
Copy link
Author

skewty commented Sep 8, 2020

Wow, that was super fast and I was so excited I closed down everything to try it out and like you said it works!
Thanks, so much. It will make a rather large difference in the code base I am working in.
I am excited to share the good news with my co-workers as well.

Thank you so much for the time you have put into this fix and the plug-in.

@skewty skewty closed this as completed Sep 8, 2020
@koxudaxi
Copy link
Owner

koxudaxi commented Sep 8, 2020

Great!!
I'm happy I can get the feedback 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released
Projects
None yet
Development

No branches or pull requests

2 participants