microsoft / microsoft/vscode

`editor.occurrencesHighlight` incorrectly highlights identifier occurrences in Python

Open
#327,737 1 comment 0 reactions 1 assignee Claimed by @Yoyokrazy View on GitHub
Dominant language
TypeScript
Stars
193k
Forks
42.4k
PR merge metrics
PR metrics pending

Description

# Current Behavior

In Python files, `editor.occurrencesHighlight` highlights unrelated occurrences when the caret is placed on tokens that are not identifier references.

For example:

```python
import time

time.time()

a = "time"
```

Placing the caret on time inside the string literal "time" highlights:

- import **time**
- **time**.**time**()

even though the caret is not on an identifier.

The same behavior can also be observed with Python keywords such as `import`, `def`, `return`, and others.

Additionally, hovering over time inside the string displays hover information for the imported time module.

Image

# Expected Behavior

Occurrences should only be highlighted when the caret is on an actual identifier reference.

String literal contents and language keywords should not be treated as identifier references.

# Regression

This appears to be a regression.

- VS Code 1.92.2: works as expected.
- VS Code 1.93.0 and later: incorrect highlighting begins.
- The behavior is independent of the installed Pylance version. The same Pylance version behaves correctly in 1.92.2 and incorrectly in 1.93.0.

# Environment

VS Code: 1.130.0
Python extension: 2026.4.0
Pylance: 2026.3.1
OS: Windows 10

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.