Skip to content

Pylance doesn't recognise attributes obtained from fields #1361

Open
@my1e5

Description

@my1e5

Consider this MRE

from attrs import define, fields

@define
class A:
    foo: int
    bar: float

f = fields(A)
print(f.foo)
Attribute(name='foo', default=NOTHING, validator=None, repr=True, eq=True, eq_key=None, order=True, order_key=None, hash=None, init=True, metadata=mappingproxy({}), type=<class 'int'>, converter=None, kw_only=False, inherited=False, on_setattr=None, alias='foo')

This all works fine.

The only thing that isn't working perfectly is Pylance doesn't seem to properly recognise this. It highlights the attribute in white and incorrect hover text is provided.
Untitled

Looking at the types, I found

print(type(f))
<class 'AAttributes'>

But I couldn't find any reference to AAttributes in the codebase.

My question is, is there something that attrs needs to do to make Pylance work here? Or is this a bug/limitation with Pylance and I should open a ticket with them to get support for this?

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    TypingTyping/stub/Mypy/PyRight related bugs.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions