microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.7k stars 767 forks source link

Dataclass fields that use `converter` don't have expected semantic tokens #6525

Open debonte opened 1 day ago

debonte commented 1 day ago

@debonte the __converterDescriptor_x regression was addressed in pyright 1.1.382.

But there remains one more issue. If an attribute uses a converter then it is displayed in white, not light blue. Here is a simple example with longer names so you can see the effect clearly.

from attrs import define, field

@define
class A:
    normal_attribute: int = field()
    converted_attribute: int = field(converter=int)

a = A(1, 2)
print(a.normal_attribute)
print(a.converted_attribute)

image

According to Eric (https://github.com/microsoft/pyright/issues/8881#issuecomment-2327140623)

The highlight color is provided by pylance's "semantic token provider". This functionality isn't part of pyright, so the pylance team will need to address that aspect separately if it's still an issue.

Originally posted by @my1e5 in https://github.com/microsoft/pylance-release/issues/5391#issuecomment-2393888089

debonte commented 1 day ago

Additionally, go to def fails on a.converted_attribute. Both issues are happening because we're not creating a declaration for converted_attribute when the descriptor type is synthesized. I'll send a PR to Pyright.