How to force the whole package to use the __future__ directive?

Can i post:

from __future__ import absolute_import 

inside __init__.py at the top level dir on my package and guarantee that absolute_import will apply to all code that runs inside that package or subpackages?

Or should I put this directive in every model that does absolute imports?

I support the Python package, and I try to make my code as easy as possible to upgrade to Python3 when the time comes. I cannot do this right away because my dependencies are not yet in Python3.

+6
source share
1 answer

No, __future__ imports are valid for only one file. You will need to put this line at the beginning of each Python source file.

In the documentation:

A future statement is a directive for the compiler to state that a particular module must be compiled using the syntax or semantics that will be available in the specified future version of Python.

+8
source

Source: https://habr.com/ru/post/920482/


All Articles