简体   繁体   English

接口继承声明

[英]Interface Inherited declaration

I'm trying to use an old code which has been developed by a Github developer.我正在尝试使用由 Github 开发人员开发的旧代码。 The code uses implements in zope.interface library to declare interfaces on a class's elements.代码使用 zope.interface 库中的实现来声明类元素上的接口。 Since implements in the library doesn't work anymore at Python 3.6, I confront with this error:由于库中的实现在 Python 3.6 中不再工作,我遇到了这个错误:

TypeError: Class advice impossible in Python3.  Use the @implementer class decorator instead.

Several websites have explained how to substitute implements with @implementer to work at Python 3.6, like here .几个网站已经解释了如何用 @implementer 替换工具以在 Python 3.6 上工作,就像这里 But I haven't found any example to explain how to update the code when zope.interface.implements has been used as an inheritance.但是我还没有找到任何例子来解释当 zope.interface.implements 被用作继承时如何更新代码。 The code looks like this:代码如下所示:

from zope.interface import implements
class Car(implements(Moveable)):
     def __init__(self, x, v, lane, model: IDM, lane_change: LaneChange,
             length):
...

I would like to update this code to work at Python 3.6.我想更新此代码以在 Python 3.6 上工作。 I've tried this我试过这个

@implementer(Moveable) 
class Car:
     def __init__(self, x, v, lane, model: IDM, lane_change: LaneChange,
             length):

but it does n't work.但它不起作用。 Please help me to figure out how to make the above code running in Python 3.6.请帮我弄清楚如何使上述代码在 Python 3.6 中运行。

Below steps solved the issue for me,以下步骤为我解决了这个问题,

pip uninstall apex
git clone https://www.github.com/nvidia/apex
cd apex
python3 setup.py install

To use implementer instead of implements as suggested by Python, you need to import it as well opposed to importing implements要使用实现者而不是 Python 建议的工具,您需要导入它,而不是导入工具

from zope.interface import implementer

In your code it shows you are still using implements, that seems to be the problem according to provided information.在您的代码中,它显示您仍在使用工具,根据提供的信息,这似乎是问题所在。 Hope it helps.希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM