summaryrefslogtreecommitdiff
path: root/pylint/utils.py
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2015-08-25 21:06:19 +0300
committerClaudiu Popa <pcmanticore@gmail.com>2015-08-25 21:06:19 +0300
commit5c8afd6b7472767e4fa4ab7d97b51a9afb80d3b2 (patch)
tree95fe7a46ee994e27542fb42f31e7b54935ad5aac /pylint/utils.py
parent489e01057de4028887af7b6842621914816abea5 (diff)
downloadpylint-5c8afd6b7472767e4fa4ab7d97b51a9afb80d3b2.tar.gz
Update pylint to use the new astroid AST names and methods
Also improve a couple of imports and added support for the old visit_ names. Priority will have the old visit_ names, such as visit_discard over visit_expr, visit_callfunc over visit_call etc.
Diffstat (limited to 'pylint/utils.py')
-rw-r--r--pylint/utils.py41
1 files changed, 37 insertions, 4 deletions
diff --git a/pylint/utils.py b/pylint/utils.py
index 236f7c8..92d4fca 100644
--- a/pylint/utils.py
+++ b/pylint/utils.py
@@ -66,6 +66,20 @@ MSG_TYPES_STATUS = {
'F' : 1
}
+DEPRECATED_ALIASES = {
+ # New name, deprecated name.
+ 'repr': 'backquote',
+ 'expr': 'discard',
+ 'assignname': 'assname',
+ 'assignattr': 'assattr',
+ 'attribute': 'getattr',
+ 'call': 'callfunc',
+ 'importfrom': 'from',
+ 'classdef': 'class',
+ 'functiondef': 'function',
+ 'generatorexp': 'genexpr',
+}
+
_MSG_ORDER = 'EWRCIF'
MSG_STATE_SCOPE_CONFIG = 0
MSG_STATE_SCOPE_MODULE = 1
@@ -540,7 +554,8 @@ class FileState(object):
#
# this is necessary to disable locally messages applying to class /
# function using their fromlineno
- if isinstance(node, (nodes.Module, nodes.Class, nodes.Function)) and node.body:
+ if (isinstance(node, (nodes.Module, nodes.ClassDef, nodes.FunctionDef))
+ and node.body):
firstchildlineno = node.body[0].fromlineno
else:
firstchildlineno = last
@@ -877,15 +892,33 @@ class PyLintASTWalker(object):
its children, then leave events.
"""
cid = astroid.__class__.__name__.lower()
+
+ # Detect if the node is a new name for a deprecated alias.
+ # In this case, favour the methods for the deprecated
+ # alias if any, in order to maintain backwards
+ # compatibility. If both of them are present,
+ # only the old ones will be called.
+ old_cid = DEPRECATED_ALIASES.get(cid)
+ visit_events = ()
+ leave_events = ()
+
+ if old_cid:
+ visit_events = self.visit_events.get(old_cid)
+ leave_events = self.leave_events.get(old_cid)
+ if not visit_events:
+ visit_events = self.visit_events.get(cid)
+ if not leave_events:
+ leave_events = self.leave_events.get(cid)
+
if astroid.is_statement:
self.nbstatements += 1
# generate events for this node on each checker
- for cb in self.visit_events.get(cid, ()):
+ for cb in visit_events or ():
cb(astroid)
# recurse on children
- for child in astroid.get_children():
+ for child in astroid.get_children():
self.walk(child)
- for cb in self.leave_events.get(cid, ()):
+ for cb in leave_events or ():
cb(astroid)