Commit 10db26d4 authored by Arnaud Fontaine's avatar Arnaud Fontaine

ZODB Components: pylint: Just ignoring no-name-in-module for monkey patch was not enough.

For example, ExtensionClass (such as ValidationFailed) need to have their AST properly
generated. This fixes 'Use of super on an old style class (super-on-old-class)' error.
parent de7c1489
Pipeline #7310 failed with stage
in 0 seconds
...@@ -190,29 +190,39 @@ MANAGER.register_failed_import_hook(fail_hook_erp5_component) ...@@ -190,29 +190,39 @@ MANAGER.register_failed_import_hook(fail_hook_erp5_component)
## transforms but this would require either checking dynamically which ## transforms but this would require either checking dynamically which
## attributes has been added (much more complex than the current approach) ## attributes has been added (much more complex than the current approach)
## or listing them statically (inconvenient). ## or listing them statically (inconvenient).
from pylint.checkers import BaseChecker from astroid.exceptions import NotFoundError
from pylint.interfaces import UNDEFINED from astroid.scoped_nodes import Module
BaseChecker_add_message = BaseChecker.add_message Module_getattr = Module.getattr
def add_message(self, msg_descr, line=None, node=None, args=None, def _getattr(self, name, *args, **kw):
confidence=UNDEFINED): try:
""" return Module_getattr(self, name, *args, **kw)
Monkey patched to dynamically ignore some error/warning messages except NotFoundError, e:
""" if self.name.startswith('erp5.'):
if msg_descr == 'no-name-in-module': raise
name, module_name = args
if not module_name.startswith('erp5.'): real_module = __import__(self.name, fromlist=[self.name], level=0)
# Do not call __import__ as this may load ZODB Component which try:
# should use 'version' and not use monkey patches... attr = getattr(real_module, name)
try: except AttributeError:
getattr(sys.modules[module_name], name) raise e
except (KeyError, AttributeError):
pass # XXX: What about int, str or bool not having __module__?
else: try:
# Do nothing as this does exist origin_module_name = attr.__module__
return except AttributeError:
BaseChecker_add_message(self, msg_descr, line=line, node=node, raise e
args=args, confidence=confidence) if self.name == origin_module_name:
BaseChecker.add_message = add_message raise
# ast_from_class() actually works for any attribute of a Module
try:
ast = MANAGER.ast_from_class(attr)
except AstroidBuildingException:
raise e
self.locals[name] = [ast]
return [ast]
Module.getattr = _getattr
if sys.modules['isort'] is None: if sys.modules['isort'] is None:
del sys.modules['isort'] del sys.modules['isort']
...@@ -2225,11 +2225,12 @@ hoge() ...@@ -2225,11 +2225,12 @@ hoge()
%(module2)s.hoge() %(module2)s.hoge()
%(module2_with_version)s.hoge() %(module2_with_version)s.hoge()
# Attributes added through Products.XXX.patches: Must not raise error # Attributes added through Products.XXX.patches: Must not raise error nor
# warnings when being used.
from Products.DCWorkflow.DCWorkflow import ValidationFailed from Products.DCWorkflow.DCWorkflow import ValidationFailed
# To avoid 'unused-import' warnings... class FooBar(ValidationFailed):
ValidationFailed('anything') def __init__(self, *args, **kw):
super(FooBar, self).__init__(*args, **kw)
""" % (dict(namespace=namespace, """ % (dict(namespace=namespace,
reference1=imported_reference1, reference1=imported_reference1,
module2=imported_module2, module2=imported_module2,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment