[Python] Pylance doesn't like calling `[]` on a dict-inherited class

Discussão em 'Python' iniciado por Stack, Maio 25, 2025.

  1. Stack

    Stack Membro Participativo

    PyAlex has the class OpenAlexEntity:

    class OpenAlexEntity(dict):
    """Base class for OpenAlex entities."""

    pass


    and Author:

    class Author(OpenAlexEntity):
    """Class representing an author entity in OpenAlex."""

    pass


    So given the following code:

    insts = Institutions().search("MIT").get()
    inst = insts[0]
    inst["display_name"]


    It correctly works and returns


    'Massachusetts Institute of Technology'
    ​

    However, PyLance underlines it in red showing the following error:

    No overloads for "__getitem__" match the provided argumentsPylancereportCallIssue
    builtins.pyi(1062, 9): Overload 2 is the closest match


    [​IMG]

    How can I fix this?

    Continue reading...

Compartilhe esta Página