Suppose I have a project with a folder structure like so.
/project
__init__.py
main.py
/__helpers
__init__.py
helpers.py
...
The module helpers.py
defines some exception and contains some method that raises that exception.
# /project/__helpers/helpers.py
class HelperException(Exception):
pass
def some_function_that_raises():
raise HelperException
On the other hand my main.py
module defines its own exceptions and imports methods that may raise an exception from helpers.py
.
# /projects/main.py
from project.__helpers.helpers import some_function_that_raises
class MainException(Exception):
pass
Now, I do not want users to have to do from project.__helpers.helpers import HelperException
if they want to catch that exception. It would make more sense to be able to import the exception from the public module that is raising it.
But I cannot just move HelperException
to main.py
, which would create a circular import.
What would be the best way to allow users to import all exceptions from main.py
while those being raised in /__helpers
?