How to use the astroid.MANAGER function in astroid

To help you get started, weā€™ve selected a few astroid examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github svn2github / chromium-depot-tools / third_party / logilab / astroid / brain / py2qt4.py View on Github external
from astroid import MANAGER, register_module_extender
from astroid.builder import AstroidBuilder


def pyqt4_qtcore_transform():
    return AstroidBuilder(MANAGER).string_build('''

def SIGNAL(signal_name): pass

class QObject(object):
    def emit(self, signal): pass
''')


register_module_extender(MANAGER, 'PyQt4.QtCore', pyqt4_qtcore_transform)
github PyCQA / pylint-django / pylint_django / transforms / __init__.py View on Github external
def fake_module_builder():
        """
            Build a fake module to use within transformations.
            @package_name is a parameter from the outher scope b/c according to
            the docs this can't receive any parameters.
            http://pylint.pycqa.org/projects/astroid/en/latest/extending.html?highlight=MANAGER#module-extender-transforms
        """
        transforms_dir = os.path.join(os.path.dirname(__file__), 'transforms')
        fake_module_path = os.path.join(transforms_dir, '%s.py' % re.sub(r'\.', '_', package_name))

        with open(fake_module_path) as modulefile:
            fake_module = modulefile.read()

        return astroid.builder.AstroidBuilder(astroid.MANAGER).string_build(fake_module)

    astroid.register_module_extender(astroid.MANAGER, package_name, fake_module_builder)
github tortoise / tortoise-orm / tortoise / contrib / pylint / __init__.py View on Github external
def apply_type_shim(cls: ClassDef, _context: Any = None) -> Iterator[ClassDef]:
    """
    Morphs model fields to representative type
    """
    base_nodes: List[ClassDef] = [cls]

    # Use the type inference standard
    try:
        base_nodes.extend(list(cls.getattr("field_type")[0].infer()))
    except AstroidError:
        pass

    return iter(base_nodes)


MANAGER.register_transform(nodes.ClassDef, inference_tip(apply_type_shim), is_model_field)
MANAGER.register_transform(nodes.ClassDef, transform_model, is_model)
github PyCQA / astroid / astroid / brain / brain_functools.py View on Github external
return (
            node.func.attrname == member
            and isinstance(node.func.expr, astroid.Name)
            and node.func.expr.name == "functools"
        )


_looks_like_partial = partial(_looks_like_functools_member, member="partial")


MANAGER.register_transform(
    astroid.FunctionDef, _transform_lru_cache, _looks_like_lru_cache
)


MANAGER.register_transform(
    astroid.Call,
    astroid.inference_tip(_functools_partial_inference),
    _looks_like_partial,
)
github PyCQA / astroid / astroid / brain / brain_numpy_core_numerictypes.py View on Github external
ubyte = uint8
    uint = uint32
    uint0 = uint32
    uintc = uint32
    uintp = uint32
    ulonglong = uint64
    unicode = str_
    unicode_ = str_
    ushort = uint16
    void0 = void
    """
    )


astroid.register_module_extender(
    astroid.MANAGER, "numpy.core.numerictypes", numpy_core_numerictypes_transform
)
github marslo / myvim / Configurations / Offline_Packages / bundle / python-mode / submodules / astroid / astroid / brain / brain_pkg_resources.py View on Github external
def postprocess(tempname, filename):
    pass

def set_extraction_path(path):
    pass

def cleanup_resources(force=False):
    pass

def get_distribution(dist):
    return Distribution(dist)

_namespace_packages = {}
''')

register_module_extender(MANAGER, 'pkg_resources', pkg_resources_transform)
github PyCQA / astroid / astroid / brain / brain_pkg_resources.py View on Github external
def set_extraction_path(path):
    pass

def cleanup_resources(force=False):
    pass

def get_distribution(dist):
    return Distribution(dist)

_namespace_packages = {}
"""
    )


register_module_extender(MANAGER, "pkg_resources", pkg_resources_transform)
github ethanchewy / PythonBuddy / venv / lib / python2.7 / site-packages / astroid / brain / brain_dateutil.py View on Github external
"""Astroid hooks for dateutil"""

import textwrap

from astroid import MANAGER, register_module_extender
from astroid.builder import AstroidBuilder

def dateutil_transform():
    return AstroidBuilder(MANAGER).string_build(textwrap.dedent('''
    import datetime
    def parse(timestr, parserinfo=None, **kwargs):
        return datetime.datetime()
    '''))

register_module_extender(MANAGER, 'dateutil.parser', dateutil_transform)
github ethanchewy / PythonBuddy / venv / lib / python2.7 / site-packages / astroid / brain / brain_qt.py View on Github external
def pyqt4_qtcore_transform():
    return AstroidBuilder(MANAGER).string_build('''