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

Semantic Highlighting for Class Method created by assigning method is wrongly coloured as property #5111

Closed
OzelotVanilla opened this issue Nov 13, 2023 · 9 comments
Assignees
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@OzelotVanilla
Copy link

Type: Bug

Behaviour

Expected vs. Actual

The method created like exactlyThisMethod in this code, will be coloured as property in semantic highlighting, rather than method.

class SomeClass:
    def someMethod(self): pass
    exactlyThisMethod = someMethod

Steps to reproduce:

Use tkinter as an example.

  1. Create a = tkinter.Tk()
  2. Create b = tkinter.Label(a)
  3. Call b.pack()

pack will be wrongly coloured as property here.

Diagnostic data

  • Python version (& distribution if applicable, e.g. Anaconda): 3.12.0
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Global
  • Value of the python.languageServer setting: Pylance
Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

XXX

User Settings


languageServer: "Pylance"

Extension version: 2023.20.0
VS Code version: Code 1.84.2 (1a5daa3a0231a0fbba4f14db7ec463cf99d7768e, 2023-11-09T10:51:52.184Z)
OS version: Windows_NT x64 10.0.19045
Modes:

System Info
Item Value
CPUs Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz (8 x 1498)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) undefined
Memory (System) 31.60GB (19.24GB free)
Process Argv --crash-reporter-id a37d0f1f-77dd-4a89-91bb-2352dc8a97c1
Screen Reader no
VM 0%
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vstes627:30244334
vslsvsres303:30308271
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263cf:30335440
vscoreces:30445986
vscod805cf:30301675
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593:30376534
pythonvs932:30410667
py29gd2263:30880072
vsclangdc:30486549
c4g48928:30535728
dsvsc012cf:30540253
pynewext54:30695312
azure-dev_surveyone:30548225
2e4cg342:30602488
89544117:30613380
showlangstatbar:30737416
pythonfmttext:30731395
fixshowwlkth:30771522
showindicator:30805244
pythongtdpath:30769146
i26e3531:30792625
pythonnosmt12:30797651
pythonidxpt:30866567
pythonnoceb:30805159
dsvsc013:30795093
dsvsc014:30804076
dsvsc015:30845448
pythontestfixt:30871694
pythonregdiag2:30871582
pyreplss1:30886140
pythonmypyd1:30879173
pythoncet0:30885854
pythontbext0:30879054
dsvsc016cf:30886111
dsvsc017cf:30886113
dsvsc018cf:30886115
aa_t_chat:30882232

@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python Nov 13, 2023
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Nov 13, 2023
@KacieKK KacieKK added bug Something isn't working and removed needs repro Issue has not been reproduced yet labels Nov 15, 2023
@KacieKK
Copy link
Contributor

KacieKK commented Jul 11, 2024

Thanks for the issue, But I think pylance is doing the right thing here that Pack is a declared as a variable.
image

image
the behavior is consistent with your example, exactlyThisMethod colored as variable because is declared as a variable and assigned a method. Semantic highlighting doesn't reflect the type of the value assigned to.

@KacieKK KacieKK added by design and removed bug Something isn't working labels Jul 11, 2024
@debonte
Copy link
Contributor

debonte commented Jul 11, 2024

#5841 is tracking the possibility of handling this scenario better.

@OzelotVanilla
Copy link
Author

#5841 is tracking the possibility of handling this scenario better.

Agreed with the content discussed in that issue.

That might be the different understanding of the name that we are declaring/defining.

If that is a design in Pylance, I think it would be better that an option is provided for the user to choose the semantic tag assigned to variable-look but function-inside identifier.

(And I am saying this standing on the point of view of a theme designer. For my design, function and variable are coloured differently, as most other themes do. Also, semantic highlighting would bring me better develop experience, especially those languages support functional programming)

@KacieKK
Copy link
Contributor

KacieKK commented Jul 11, 2024

Thanks @debonte and @OzelotVanilla !

@KacieKK KacieKK added duplicate This issue or pull request already exists and removed by design labels Jul 11, 2024
@KacieKK KacieKK closed this as completed Jul 11, 2024
@debonte
Copy link
Contributor

debonte commented Feb 12, 2025

As @oskarkk pointed out, I missed this scenario when fixing #5841. Reactivating.

@debonte debonte reopened this Feb 12, 2025
@debonte debonte assigned debonte and unassigned KacieKK Feb 12, 2025
@debonte debonte added bug Something isn't working and removed duplicate This issue or pull request already exists labels Feb 12, 2025
@debonte
Copy link
Contributor

debonte commented Feb 12, 2025

The method created like exactlyThisMethod in this code, will be coloured as property in semantic highlighting, rather than method.

Following the decision in #6924, the fix here will be to leave the token type unchanged but add the callable modifier.

Btw, a note for those of us that know Python better than the semantic tokenization docs... The property token type is not referring to the Python concept of properties, but rather indicates that the identifier "declares or references a member property, member field, or member variable."

@bschnurr bschnurr added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Feb 13, 2025
@laundmo
Copy link

laundmo commented Feb 14, 2025

I believe this may be fixed at the same time as

as both deal with semantic highlighting of (re-)assigning methods, which should still be picked up as methods.

@debonte
Copy link
Contributor

debonte commented Feb 14, 2025

They were slightly different, but both will be fixed in our next prerelease build.

FYI, we don't close issues until the fix ships, but you can know that a fix is imminent if you see one of the "fixed in next version" labels on the issue.

@bschnurr
Copy link
Member

This issue has been fixed in prerelease version 2025.2.100, which we've just released. You can find the changelog here: CHANGELOG.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

5 participants