[Python] 'ABCMeta' object is not subscriptable when trying to annotate a hash variable

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

  1. Stack

    Stack Membro Participativo

    The following dataclass:

    from abc import ABC
    from collections.abc import Mapping
    from dataclasses import dataclass, field

    @dataclass(eq=True, order=True, frozen=True)
    class Expression(Node, ABC):
    def node(self):
    raise NotImplementedError


    is used as a base class for:

    @dataclass(eq=True, frozen=True)
    class HashLiteral(Expression):
    pairs: Mapping[Expression, Expression]
    ...


    Node is defined as:

    @dataclass(eq=True, frozen=True)
    class Node:
    def __str__(self) -> str:
    raise NotImplementedError


    When trying to use the HashLiteral class I get the error:

    pairs: Mapping[Expression, Expression]
    TypeError: 'ABCMeta' object is not subscriptable


    What is wrong with my annotation of pairs above?

    Continue reading...

Compartilhe esta Página