microsoft / microsoft/pyright

Magic calls to deprecated __getitem__ not flagged as deprecated

Open
#10,986 1 comment 1 reaction 0 assignees View on GitHub
enhancement request
Dominant language
Python
Stars
15.6k
Forks
1.8k
Avg merge
12h 13m
Merged PRs (30d)
52

Description

**Describe the bug**

Calls to `__getitem__` resulting from indexing syntax don't report deprecation warnings when they should.

Acording to :

> - Any syntax that indirectly triggers a call to the function. For example, if the `__add__` method of a class `C` is deprecated, then the code `C() + C()` should trigger a diagnostic. Similarly, if the setter of a property is marked deprecated, attempts to set the property should trigger a diagnostic.

This principle seems equally applicable here.

**Code or Screenshots**

Code sample in [pyright playground](https://pyright-play.net/?strict=true&code=GYJw9gtgBA7ghiAdgS0QcwM5WRADmEAFygBMBTXEMgYzkLJIChnqAbODLAMTDAC5GUIVAAC5SjToMAFACIAcmQBuZEKWQkocRAE9CAC1RooAVwxlgJ1rICUg4eWBQA%2Bs7RlCyehFfTzrYAAaKABrMh0%2BKAxCEBsBYQSoXA4MZgAPKABeKB4waTs0gG0AcgAjBGKAXSgAYigAZX0wK014JChSk2ISMDIMRGLCRjSAOld3T29fMrgAL2KbWqgAdQRELA4oMjTcGnoSIA)

```python
from warnings import deprecated

class Foo:
@deprecated("Never did anything useful")
def __getitem__(self, key: str):
pass

x = Foo()
x['bar'] # Should warn but doesn't
x.__getitem__('baz') # Warns as expected
```

**VS Code extension or command-line**

I haven't tried it locally using upstream pyright or pylance; pyright-play.net says this is 1.1.406.

Contributor guide

Open the contributing guide

Research direction

Reproduce the reported example in the linked pyright playground, comparing deprecated direct __getitem__ calls with indexing syntax. Trace how the checker handles these two forms and ensure indexing produces the same deprecation diagnostic; the work is done when the behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.