Magic calls to deprecated __getitem__ not flagged as deprecated
Describe the bug
Calls to __getitem__ resulting from indexing syntax don't report deprecation warnings when they should.
Acording to https://typing.python.org/en/latest/spec/directives.html#deprecated:
- Any syntax that indirectly triggers a call to the function. For example, if the
__add__method of a classCis deprecated, then the codeC() + 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
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.
In general, implicit use of magic method calls are not flagged as deprecated. I've added support for a handful of them, but most are not supported. Surfacing them requires significant work for each magic method call.
Changing this to an enhancement request.