From 92b440a0baf590fcb3082dfe2ca673813e1e5b7c Mon Sep 17 00:00:00 2001 From: Stanislav Levin Date: Feb 12 2020 16:08:32 +0000 Subject: pylint: Teach Pylint how to handle request.context With Astroid change [0] a inference for builtin containers was improved. This means that all the elements of such containers will be inferred if they are not Python constants (previously ignored). This change introduces several issues, one of them is a volatile error exposed at multi-job Pylinting, but could be guaranteed produced at single-job mode as: ``` PYTHONPATH=. /usr/bin/python3 -m pylint --rcfile=./pylintrc \ --load-plugins pylint_plugins ipaserver/plugins/dns.py ipalib/request.py ipalib/request.py:76: [E1101(no-member), destroy_context] Instance of 'bool' has no 'disconnect' member) ----------------------------------- Your code has been rated at 9.97/10 ``` Or even adding 'context.some_attr = True' into ipalib/request.py. It's should be treated as no one member of `context`'s attrs is a `Connection` instance and has `destroy_context` member. To tell Pylint that there are such members the corresponding transformation is added. [0] https://github.com/PyCQA/astroid/commit/79d5a3a7 Related: https://pagure.io/freeipa/issue/8116 Signed-off-by: Stanislav Levin Reviewed-By: Christian Heimes --- diff --git a/pylint_plugins.py b/pylint_plugins.py index 70bd1d5..7f3cf01 100644 --- a/pylint_plugins.py +++ b/pylint_plugins.py @@ -284,6 +284,18 @@ register_module_extender(MANAGER, 'ipaplatform.tasks', ipaplatform_tasks_transform) +def ipalib_request_transform(): + """ipalib.request.context attribute + """ + return AstroidBuilder(MANAGER).string_build(textwrap.dedent(''' + from ipalib.request import context + context._pylint_attr = Connection("_pylint", lambda: None) + ''')) + + +register_module_extender(MANAGER, 'ipalib.request', ipalib_request_transform) + + class IPAChecker(BaseChecker): __implements__ = IAstroidChecker