【发布时间】:2022-10-07 02:15:44
【问题描述】:
from typing import Generic, TypeVar, Any
R = TypeVar(\'R\')
X = TypeVar(\'X\')
class SizedIterator(Generic[X]):
def __init__(self) -> None:
pass
class TfmIterator(Generic[R], SizedIterator):
def __init__(self) -> None:
pass
以上是https://github.com/autorope/donkeycar/blob/dev/donkeycar/pipeline/sequence.py 中代码的简化版本。
显然,该代码在 Python 3.6 和/或 3.7 中运行良好。但是,当我尝试在 Python 3.9 中运行它时,它会给出以下错误:
Traceback (most recent call last):
File \"/Users/Shared/Personal/mycar/simple1.py\", line 10, in <module>
class TfmIterator(Generic[R], SizedIterator):
TypeError: Cannot create a consistent method resolution
order (MRO) for bases Generic, SizedIterator
我的问题是如何在不遇到 MRO 错误的情况下保持相同的类型提示?
标签: python multiple-inheritance python-typing