Commit 1e697b46 authored by Arnaud Fontaine's avatar Arnaud Fontaine

pylint: Handle primitive types for no-name-in-module.

This fixes errors such as:
E: No name '_dtmldir' in module 'Products.ERP5Type' (no-name-in-module)

Where _dtmldir is 'PATH/TO/Products/ERP5Type/dtml/', dynamically added to
Products.ERP5Type module.
parent 472808c5
...@@ -210,19 +210,32 @@ def _getattr(self, name, *args, **kw): ...@@ -210,19 +210,32 @@ def _getattr(self, name, *args, **kw):
except AttributeError: except AttributeError:
raise e raise e
# XXX: What about int, str or bool not having __module__?
try: try:
origin_module_name = attr.__module__ origin_module_name = attr.__module__
except AttributeError: except AttributeError:
raise e from astroid import nodes
if self.name == origin_module_name: if isinstance(attr, dict):
raise ast = nodes.Dict(attr)
elif isinstance(attr, list):
ast = nodes.List(attr)
elif isinstance(attr, tuple):
ast = nodes.Tuple(attr)
elif isinstance(attr, set):
ast = nodes.Set(attr)
else:
try:
ast = nodes.Const(attr)
except Exception:
raise e
else:
if self.name == origin_module_name:
raise
# ast_from_class() actually works for any attribute of a Module # ast_from_class() actually works for any attribute of a Module
try: try:
ast = MANAGER.ast_from_class(attr) ast = MANAGER.ast_from_class(attr)
except AstroidBuildingException: except AstroidBuildingException:
raise e raise e
self.locals[name] = [ast] self.locals[name] = [ast]
return [ast] return [ast]
......
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