zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
50.57k stars 3.13k forks source link

Pyright cannot access attribute of a class `cached_property` #14371

Open calvinkawai opened 4 months ago

calvinkawai commented 4 months ago

Check for existing issues

Describe the bug / provide steps to reproduce it

I have a class similar in following structure, I want to go to definition of test function but pyright will throw error Cannot access attribute "test" for class "cached_property"   Attribute "test" is unknown


class A:

    @cached_property
    def foo(self):
           return B

    def f(self):
           # test is a function of B
           self.foo.test()

Environment

Zed: v0.143.7 (Zed) OS: macOS 14.5.0 Memory: 16 GiB Architecture: aarch64

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your Zed.log file to this issue.

Zed.log


CharlesChen0823 commented 4 months ago

can you post a mini codebase for this?

calvinkawai commented 4 months ago

I just went through my code, I created something similar as code below and attach error image. I opened same code in Pycharm and it's fine to look up the definition.

from django.db import models
from django.utils.functional import cached_property

class Friend:

    def add_new_friend(self, person_id):
        print("add new friend")

# Create your models here.
class Person(models.Model):

    @cached_property
    def friend(self):
        return Friend()

    def add_me_to_friend_list(self)
        self.friend.add_new_friend(self.id)

Untitled

CharlesChen0823 commented 4 months ago

confirm that. not working with pyright, but in Pycharm and vscode, this work well.

And IMO, this is might pyright not supported this. because, using neovim with pyright, will also report this error.

calvinkawai commented 4 months ago

Is it possible changing to other language server?

notpeter commented 5 days ago

I am able to reproduce this with the file you provided:

whatever.py ```python from django.db import models from django.utils.functional import cached_property class Friend: def add_new_friend(self, person_id): print("add new friend") # Create your models here. class Person(models.Model): id = models.AutoField(primary_key=True) @cached_property def friend(self): return Friend() def add_me_to_friend_list(self): self.friend.add_new_friend(self.id) ```

Error:

Screenshot 2024-11-19 at 10 57 49

But I was able to resolve it with the following:

uv add --dev 'django-stubs[compatible-mypy]' django-types 

Can you see if installing those packages into your venv resolves your issues?