Невероятно сложная ошибка аннотации типа Python - PullRequest
1 голос
/ 04 мая 2020

Следующий код, включающий обобщенные c подклассы, не может проверить тип:

from __future__ import annotations

from typing import Generic, Tuple, Type, TypeVar

A = TypeVar('A')
B = TypeVar('B', bound='W')


class W(Generic[A]):

    @classmethod
    def g(cls: Type[B]) -> B:
        return cls()


class X(W[A], Generic[A]):

    C = TypeVar('C', bound='X.Y')  # I really want X[A].Y here.

    class Y(W[Tuple[A, A]]):

        @classmethod
        def g(cls: Type[X.C]) -> X.C:
            return super().g()

Я, очевидно, допустил ошибку, но не понимаю ошибку:

error: Return type "Y[A]" of "g" incompatible with return type "Y[Tuple[A, A]]" in supertype "W"

...