[Python] Type hinting using class attributes

Discussão em 'Python' iniciado por Stack, Agosto 11, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to create the following type hints in Python, but I has thus far been unable to find a way to actively use my class attributes as type hints:

    @dataclass
    class MyClass:
    x: int
    y: int
    def my_method(self) -> np.ndarray([tuple[self.x, self.y], np.float32]):
    pass


    Is this possible in Python, or do I have to just write the generic int instead of self.x and self.y in the type hint?

    Continue reading...

Compartilhe esta Página