https://pantsbuild.org/ logo
#general
Title
# general
c

clean-city-64472

10/06/2021, 5:49 PM
Are relative imports supported for dependency inference? (e.g.
from .subfolder import something
vs
from module.subfolder import something
?)
c

clean-city-64472

10/06/2021, 6:00 PM
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

hundreds-father-404

10/06/2021, 6:03 PM
Oh, that would be this horrible gotcha, the tooltip about init.py https://www.pantsbuild.org/docs/python-backend
c

clean-city-64472

10/06/2021, 6:04 PM
Any downside to turning this on?
h

hundreds-father-404

10/06/2021, 6:05 PM
It can: https://github.com/pantsbuild/pants/pull/10813, but almost certainly worth turning on in your case
c

clean-city-64472

10/06/2021, 6:07 PM
k it does fix this issue
💯 1
h

hundreds-father-404

10/06/2021, 6:08 PM
fyi https://github.com/pantsbuild/pants/issues/10823 tracks removing this gotcha
p

proud-dentist-22844

10/06/2021, 11:17 PM
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.
3 Views