Hi friends :wave: Trying to get `from mod1 import...
# general
m
Hi friends 👋 Trying to get
from mod1 import submodule1; submodule1.class1()
to work but getting
AttributeError: module submodule1 has no attribute class1
I do have
__init__.py
files everywhere. Wondering how I can avoid populating the
__init__.py
files with
from . import class1, class2, etc.
(which isn't a sustainable option) to prevent this error? I've understood this to be due to some type of lazy-loading - the import commands actually seem to work fine when attaching the debugger. Thanks in advance!
b
Is
submodule1
a file or a directory? If it’s a file, then you should be able to import the class; Pants only models targets as low as file level. If it’s a directory, then I wonder how you’d plan to import directly from
submodule1
without using
__init__.py
?
m
Hi Krishnan! Thanks for that insight. So
submodule1
is a directory. I was not aware of the Pants limitation that it only can target to file level, that's tricky. Don't suppose there's any known configuration around that?
b
You say that the import commands work fine when attaching a debugger, but I’m curious what kind of debugger you’re attaching; does that import work in a regular Python shell outside of Pants?
m
Okay - I must've been hallucinating. You're absolutely right that this type of import is not possible inside or outside of Pants. It's fathomable that the PDB debugger I was using had a prior cache where I had used explicit imports inside
__init__.py
. Thank you for bearing with me here! I'll assess my options in trying to support this in a maintainable way.