logilab-astng #106191 Absolute imports aren't handled correctly. [validation pending]

I'm using pylint, but the problem is in logilab-astng. The problem occurs when I use the from __future__ import absolute_import statement. I'm on Python 2.7.

Python's _ast seems to always create _ast.ImportFrom objects with level = 0, but parts of logilab-astng seem to be written with the assumption that From nodes should have a level of None, 0, or >=1:

def relative_to_absolute_name(self, modname, level):
    if self.absolute_import_activated() and level is None:
        return modname
    # …

But this seems to never be the case, since ASTNG's rebuilder always uses _ast's level value, which means that level is never None:

def visit_from(self, node, parent):
    """visit a From node by returning a fresh instance of it"""
    names = [(alias.name, alias.asname) for alias in node.names]
    newnode = new.From(node.module or '', names, node.level)
    # …

This causes problems for me because I get incorrect errors from pylint. My file structure is:

├── console
│   └── resolver.py
└── tests
    ├── console.py
    └── foo.py

In tests/console.py I have the line:

from console.resolver import reverse

Pylint complains with:

[E0611] No name 'resolver' in module 'tests.console'

It's not clear where in logilab-astng this should be fixed, there's a few possible places, but I think the best place is in logilab/astng/rebuilder.py:TreeRebuilder.visit_from:

  def visit_from(self, node, parent):
      """visit a From node by returning a fresh instance of it"""
      names = [(alias.name, alias.asname) for alias in node.names]
+     if parent.absolute_import_activated() and node.level == 0:
+         level = None
+     else:
+         level = node.level
+     newnode = new.From(node.module or '', names, level)
-     newnode = new.From(node.module or '', names, node.level)
      _set_infos(node, newnode, parent)
      # store From names to add them to locals after building
      self._from_nodes.append(newnode)
      return newnode
priorityimportant
typebug
done in0.24.1
load left0.000
closed by#55333bb6658e test and fix absolute import handling. Closes #106191