简体   繁体   中英

Interface Inherited declaration

I'm trying to use an old code which has been developed by a Github developer. The code uses implements in zope.interface library to declare interfaces on a class's elements. Since implements in the library doesn't work anymore at Python 3.6, I confront with this error:

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 . But I haven't found any example to explain how to update the code when zope.interface.implements has been used as an inheritance. 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. 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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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