wes.p
wes.p

Reputation: 75

Usage of Interface package results in issubclass() error

Im currently working on a project where we decided to use the interface library instead of abc. However, when I run my program, the following error pops up:

Traceback (most recent call last):
  File "runner.py", line 1, in <module>
    from exchanges import *
  File "/Users/**/Projects/jimmy/characterlib/__init__.py", line 2, in <module>
    from exchanges import hitbtc
  File "/Users/**/Projects/jimmy/characterlib/soldier.py", line 5, in <module>
    class Soldier(implements(ICharacter)):
  File "/usr/local/lib/python3.7/site-packages/interface/interface.py", line 490, in implements
    if not issubclass(I, Interface):
TypeError: issubclass() arg 1 must be a class

Now my setup here is really basic:

soldier.py:

from interface import implements, Interface
import characterlib.ICharacter as ICharacter

class Soldier(implements(ICharacter)):

ICharacter:

from interface import Interface

class ICharacter(Interface):
    def walk(self): pass

init.py:

import characterlib.ICharacter
import characterlib.Soldier

now as you can see, very simple setup, however, I can't manage to get it to run properly. How is this possible?

Is there anyone with some more experience on this topic?

Thanks.

Upvotes: 0

Views: 106

Answers (1)

jfowkes
jfowkes

Reputation: 1565

Your imports are slighty wrong.

import characterlib.ICharacter as ICharacter

means that ICharacter is a module, not the interface. Just change the class declaration to solve that:

class Soldier(implements(ICharacter.ICharacter)):
    def walk(self):
        pass

Upvotes: 1

Related Questions