Are relative imports supported for dependency infe...
# general
c
Are relative imports supported for dependency inference? (e.g.
from .subfolder import something
vs
from module.subfolder import something
?)
c
I think I'm encountering something like this:
Copy code
# module/__init__.py
from .api import PublicThing

# module/api.py

SECRET_THING = 123

class PublicThing:
    pass

# tests/test_module.py

from module import api
print(api.SECRET_THING)
This used to work
h
Oh, that would be this horrible gotcha, the tooltip about init.py https://www.pantsbuild.org/docs/python-backend
c
Any downside to turning this on?
h
It can: https://github.com/pantsbuild/pants/pull/10813, but almost certainly worth turning on in your case
c
k it does fix this issue
💯 1
h
fyi https://github.com/pantsbuild/pants/issues/10823 tracks removing this gotcha
p
fyi - I can't remember any python projects that do not put stuff in at least some of the
__init__.py
files...
I'm sure they exist, but none that I've worked on.