2

I am working on a project that used to use python 2, but does not anymore.

I see many lines of code like these :

from __future__ import absolute_import

Can I safely remove them all ?

From what I read, it seems it was only used in python 2 to mimic Python 3 behavior

CF linked question : What does from __future__ import absolute_import actually do?

As well this source :

Using the absolute_import line in Python 2 changes the search strategy to mimic the Python 3 search strategy

Eli O.
  • 1,543
  • 3
  • 18
  • 27

1 Answers1

1

The only feature that requires using the future statement is annotations (see PEP 563).

All historical features enabled by the future statement are still recognized by Python 3. The list includes absolute_import, division, generators, generator_stop, unicode_literals, print_function, nested_scopes and with_statement. They are all redundant because they are always enabled, and only kept for backwards compatibility.

https://docs.python.org/3/reference/simple_stmts.html#future-statements

So, yes, you can safely remove it for Python 3 code.

deceze
  • 510,633
  • 85
  • 743
  • 889