another use case for this error is when you import functions within the class definition. this makes the subsequent function calls a part of the class object. In this case you can use @staticmethod on the library import function or make a static path call directly to the function. see example below
In this example "self.bar()" will throw a TypeError, but it can be fixed in two ways
# in lib.py
def bar():
print('something to do')
# in foo.py
class foo():
from .lib import bar
def __init__(self):
self.bar()
Option 1:
# in lib.py
def bar():
print('something to do')
# in foo.py
class foo():
from .lib import bar
def __init__(self):
lib.bar()
Option 2:
# in lib.py:
@staticmethod
def bar():
print('something to do')
# in foo.py
class foo():
from .lib import bar
def __init__(self):
self.bar()