Skip to content

[Python 3.9 compat] Check for __class_getitem__ #3951

@JulienPalard

Description

@JulienPalard

Python 3.9 starts to make a great use of __class_getitem__ for exemple in collections.deque.

pylint/checkers/typecheck.py should probably look for it to infer if something is subscriptable.

Reproducer:

import collections
print(collections.deque[int])

which give:

test.py:11:6: E1136: Value 'collections.deque' is unsubscriptable (unsubscriptable-object)

while the code works thanks to the __class_getitem__.

Related to #3890.
See also #3882.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions