pylint-dev / astroid

A common base representation of python source code for pylint and other projects
https://pylint.readthedocs.io/projects/astroid/en/latest/
GNU Lesser General Public License v2.1
533 stars 276 forks source link

Make it possible to register multiple module extenders for the same module #816

Open eugene57 opened 4 years ago

eugene57 commented 4 years ago

Steps to reproduce

  1. Register module extender for a module that already has one (e.g. from built-in astroid brain).

File brain_numpy_core_numerictypes.py:

import astroid

def numpy_core_numerictypes_transform():
    return astroid.parse("""
    float128 = float
    """)

def register(linter):
    astroid.register_module_extender(astroid.MANAGER, "numpy.core.numerictypes", numpy_core_numerictypes_transform)

File .pylintrc:

...
load-plugins=brain_numpy_core_numerictypes
...
  1. Lint following file:
    
    import numpy

x = numpy.float128(0)


### Current behavior

***** Module test_numpy test_numpy.py:3:4: E1101: Module 'numpy' has no 'float128' member (no-member)



Since astroid 2.0.0 second module extender does not work. It registers without error, but has no effect.
In earlier astroid that worked.

### Expected behavior
No linter error.
I think that both module extenders should be used by astroid.
Or the second one should overwrite the first one.
Or there could be a public API for unregistering existing extender (I wrote such a function myself, but it is really ugly).

### ``python -c "from astroid import __pkginfo__; print(__pkginfo__.version)"`` output
2.4.1
PCManticore commented 3 years ago

Thanks for the report, this is something that we could support.