接口继承声明
Interface Inherited declaration
我正在尝试使用由 Github 开发人员开发的旧代码。该代码使用 zope.interface 库中的实现来声明 class 元素上的接口。由于库中的工具在 Python 3.6 中不再工作,我遇到了这个错误:
TypeError: Class advice impossible in Python3. Use the @implementer class decorator instead.
一些网站已经解释了如何用@implementer 替代工具以在 Python 3.6 上工作,例如 here。但是我还没有找到任何例子来解释当 zope.interface.implements 被用作继承时如何更新代码。代码如下所示:
from zope.interface import implements
class Car(implements(Moveable)):
def __init__(self, x, v, lane, model: IDM, lane_change: LaneChange,
length):
...
我想更新此代码以在 Python 3.6 上工作。我试过这个
@implementer(Moveable)
class Car:
def __init__(self, x, v, lane, model: IDM, lane_change: LaneChange,
length):
但是不行。
请帮助我弄清楚如何在 Python 3.6.
中制作上述代码 运行
要使用 implementer 而不是 Python 建议的 implements,您需要导入它而不是导入 implements
from zope.interface import implementer
在您的代码中,它表明您仍在使用工具,根据提供的信息,这似乎是问题所在。希望对你有帮助。
下面的步骤解决了我的问题,
pip uninstall apex
git clone https://www.github.com/nvidia/apex
cd apex
python3 setup.py install
我正在尝试使用由 Github 开发人员开发的旧代码。该代码使用 zope.interface 库中的实现来声明 class 元素上的接口。由于库中的工具在 Python 3.6 中不再工作,我遇到了这个错误:
TypeError: Class advice impossible in Python3. Use the @implementer class decorator instead.
一些网站已经解释了如何用@implementer 替代工具以在 Python 3.6 上工作,例如 here。但是我还没有找到任何例子来解释当 zope.interface.implements 被用作继承时如何更新代码。代码如下所示:
from zope.interface import implements
class Car(implements(Moveable)):
def __init__(self, x, v, lane, model: IDM, lane_change: LaneChange,
length):
...
我想更新此代码以在 Python 3.6 上工作。我试过这个
@implementer(Moveable)
class Car:
def __init__(self, x, v, lane, model: IDM, lane_change: LaneChange,
length):
但是不行。 请帮助我弄清楚如何在 Python 3.6.
中制作上述代码 运行要使用 implementer 而不是 Python 建议的 implements,您需要导入它而不是导入 implements
from zope.interface import implementer
在您的代码中,它表明您仍在使用工具,根据提供的信息,这似乎是问题所在。希望对你有帮助。
下面的步骤解决了我的问题,
pip uninstall apex
git clone https://www.github.com/nvidia/apex
cd apex
python3 setup.py install