[Python] coc-pyright fail to report reportAttributeAccessIssue if __setattr__ is provided

Discussão em 'Python' iniciado por Stack, Março 28, 2025.

  1. Stack

    Stack Membro Participativo

    from pydantic import BaseModel
    class User2(BaseModel):
    name:str
    age: int
    '''
    def __setattr__(self, key, value):
    super().__setattr__(key, value)
    '''
    user2 = User2(name="Alice", age=1)
    >>> user2.foo = 1 # Should report: Cannot assign to attribute "foo" for class "User2" \ Attribute "foo" is unknown


    if I uncomment the __setattr__ function, user2.foo = 1, coc-pyright doesn't report an error. I want to use a __setattr__ method but also have it report an error. How can I do this?

    Continue reading...

Compartilhe esta Página