I have a library like this. wckg is the library name
wckg:
__init__.py
api/wckg_api.py
In __init__.py
, I import the wckg_api
scope and have an enum defined:
from wckg.api import wckg_api
class RelType(Enum):
a = 1
b = 2
WCKG = wckg_api.Wckg()
In api/wckg_api.py
:
from wckg import RelType
class Wckg(object):
pass
As you can see, from wckg_api.py
, it imports RelType
from __init__
, and at the same time it imports wckg_api
from from wckg.api.py
to create the Wckg
object. This is circular and it reports an error:
ImportError: cannot import name 'RelType' from 'wckg' (/Users/comin/nlpc/wckg/wckg/init.py)
Is there a way to resolve this issue? init defined the interfaces and wckg_api.py is supposed to define the implementations of interfaces. I dont' want to define the constant RelType in wckg_api.py because I don't want users to import those constant types when users call a function from init. Those types can be immediately available to users. But since init also need to import something from wckg_api.py, it creates this circular import issue.
Is this a typical issue?