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

Strangely placed declaration highlighting for fields #233

Closed
lancelote opened this issue Jan 6, 2021 · 4 comments · Fixed by #682
Closed

Strangely placed declaration highlighting for fields #233

lancelote opened this issue Jan 6, 2021 · 4 comments · Fixed by #682
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@lancelote
Copy link

Describe the bug

In some cases when the caret is placed on some instance attributes a strange background highlighting appears. Disabling the plugin resolves the problem.

To Reproduce

Consider the following structure

.
├── models
│   └── location.py
└── sample.py

... with location.py

from typing import Optional

from pydantic import BaseModel


class Location(BaseModel):
    city: str
    state: Optional[str] = None
    country: str = "US"

... and sample.py

from typing import Optional

import fastapi
from fastapi import Depends
from models.location import Location

router = fastapi.APIRouter()


@router.get("/api/weather/{city}")
def weather(loc: Location = Depends(), units: Optional[str] = "metric"):
    print(loc.city, loc.state, loc.country, units)

Place caret on the last line in sample.py on state. Some strange background highlighting over lines 5-7 appears.

Expected behavior

I would expect either no highlighting in imports.

Screenshots

usage

Environments

  • IDE: PyCharm 2020.3.2
  • OS: macOS 10.15.6
  • Pydantic Version 1.7.3
  • Plugin version 0.1.18
@koxudaxi
Copy link
Owner

koxudaxi commented Jan 7, 2021

@lancelote
Thank you for creating this issue.
I can reproduce this problem.
But, I don't know why highlighting is strange.
I will find the cause. Thank you.

@koxudaxi koxudaxi added the bug Something isn't working label Jan 7, 2021
@koxudaxi koxudaxi added the help wanted Extra attention is needed label Jan 15, 2021
@koxudaxi
Copy link
Owner

@lancelote
I searched for the reason for the problem yesterday.

private fun searchField(pyClass: PyClass, elementName: String, consumer: Processor<in PsiReference>): Boolean {
if (!isPydanticModel(pyClass, true)) return false
val pyTargetExpression = pyClass.findClassAttribute(elementName, false, null) ?: return false
consumer.process(pyTargetExpression.reference)

These lines work to register a field. But, It marks a strangely placed declaration highlighting.
I read the related source code of PyCharm. But, I don't understand the reason :(
If JetBrains members help me with this problem, then I'm happy.

@koxudaxi
Copy link
Owner

@lancelote
I'm sorry for my too-late reply.
I have released the fixed version v0.4.2

Thank you very much!!

@lancelote
Copy link
Author

@koxudaxi No worries, my bad actually for not assisting you with the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants