From ea3ab28d74d4e48526cfe08b11689dabb0a818d3 Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Tue, 26 Oct 2021 12:23:22 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20MAINTAIN:=20Move=20pylint=20plug?= =?UTF-8?q?in=20to=20external=20package=20(#5190)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Moved to https://github.com/aiidateam/pylint-aiida --- pyproject.toml | 2 +- setup.json | 1 + utils/pylint_aiida.py | 57 ------------------------------------------- 3 files changed, 2 insertions(+), 58 deletions(-) delete mode 100644 utils/pylint_aiida.py diff --git a/pyproject.toml b/pyproject.toml index dae3953e5a..7f617b0bc9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ requires = ["setuptools>=40.8.0", "wheel", "fastentrypoints~=0.12"] build-backend = "setuptools.build_meta" [tool.pylint.master] -load-plugins = ["pylint_django", "utils.pylint_aiida"] +load-plugins = ["pylint_aiida", "pylint_django"] # this currently fails with aiida.common.exceptions.ProfileConfigurationError: no profile has been loaded # we woud need a static settings module to use this # django-settings-module = "aiida.backends.djsite.settings" diff --git a/setup.json b/setup.json index 8fe08cb42a..af46421000 100644 --- a/setup.json +++ b/setup.json @@ -98,6 +98,7 @@ "packaging==20.3", "pre-commit~=2.2", "pylint~=2.11.1", + "pylint-aiida~=0.1.1", "pylint-django", "sqlalchemy2-stubs" ], diff --git a/utils/pylint_aiida.py b/utils/pylint_aiida.py deleted file mode 100644 index f577057b7b..0000000000 --- a/utils/pylint_aiida.py +++ /dev/null @@ -1,57 +0,0 @@ -# -*- coding: utf-8 -*- -"""pylint plugin for ``aiida-core`` specific issues.""" -import astroid - - -def register(linter): # pylint: disable=unused-argument - """Register linters (unused)""" - - -def remove_classprop_imports(import_from: astroid.ImportFrom): - """Remove any ``classproperty`` imports (handled in ``replace_classprops``)""" - import_from.names = [name for name in import_from.names if name[0] != 'classproperty'] - - -def replace_classprops(func: astroid.FunctionDef): - """Replace ``classproperty`` decorated methods. - - As discussed in https://github.com/PyCQA/pylint/issues/1694, pylint does not understand the ``@classproperty`` - decorator, and so mistakes the method as a function, rather than an attribute of the class. - If the method is annotated, this leads to pylint issuing ``no-member`` errors. - - This transform replaces ``classproperty`` decorated methods with an annotated attribute:: - - from aiida.common.lang import classproperty - - class MyClass: - @classproperty - def my_property(cls) -> AnnotatedType: - return cls.my_value - - MyClass.my_property.attribute # <-- pylint issues: Method 'my_property' has no 'attribute' member (no-member) - - class MyClass: - my_property: AnnotatedType - - """ - # ignore methods without annotations or decorators - if not (func.returns and func.decorators and func.decorators.nodes): - return - # ignore methods that are specified as abstract - if any(isinstance(node, astroid.Name) and 'abstract' in node.name for node in func.decorators.nodes): - return - if any(isinstance(node, astroid.Attribute) and 'abstract' in node.attrname for node in func.decorators.nodes): - return - # convert methods with @classproperty decorator - if isinstance(func.decorators.nodes[0], astroid.Name) and func.decorators.nodes[0].name == 'classproperty': - assign = astroid.AnnAssign(lineno=func.lineno, col_offset=func.col_offset, parent=func.parent) - assign.simple = 1 - assign.target = astroid.AssignName(func.name, lineno=assign.lineno, col_offset=assign.col_offset, parent=assign) - assign.annotation = func.returns - assign.annotation.parent = assign - func.parent.locals[func.name] = [assign.target] - return assign - - -astroid.MANAGER.register_transform(astroid.ImportFrom, remove_classprop_imports) -astroid.MANAGER.register_transform(astroid.FunctionDef, replace_classprops)