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
...@@ -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):
"""
Monkey patched to dynamically ignore some error/warning messages
"""
if msg_descr == 'no-name-in-module':
name, module_name = args
if not module_name.startswith('erp5.'):
# Do not call __import__ as this may load ZODB Component which
# should use 'version' and not use monkey patches...
try: try:
getattr(sys.modules[module_name], name) return Module_getattr(self, name, *args, **kw)
except (KeyError, AttributeError): except NotFoundError, e:
pass if self.name.startswith('erp5.'):
else: raise
# Do nothing as this does exist
return real_module = __import__(self.name, fromlist=[self.name], level=0)
BaseChecker_add_message(self, msg_descr, line=line, node=node, try:
args=args, confidence=confidence) attr = getattr(real_module, name)
BaseChecker.add_message = add_message except AttributeError:
raise e
# XXX: What about int, str or bool not having __module__?
try:
origin_module_name = attr.__module__
except AttributeError:
raise e
if self.name == origin_module_name:
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