Index: third_party/pylint/checkers/newstyle.py |
diff --git a/third_party/pylint/checkers/newstyle.py b/third_party/pylint/checkers/newstyle.py |
index cc8f640731f3704a693f0e5dc6e2fa82c0e726b6..f74e7f150ef7ddf362a5ee7cdc8f02209e260174 100644 |
--- a/third_party/pylint/checkers/newstyle.py |
+++ b/third_party/pylint/checkers/newstyle.py |
@@ -19,9 +19,13 @@ import sys |
import astroid |
-from pylint.interfaces import IAstroidChecker |
+from pylint.interfaces import IAstroidChecker, INFERENCE, INFERENCE_FAILURE, HIGH |
from pylint.checkers import BaseChecker |
-from pylint.checkers.utils import check_messages |
+from pylint.checkers.utils import ( |
+ check_messages, |
+ has_known_bases, |
+ node_frame_class, |
+) |
MSGS = { |
'E1001': ('Use of __slots__ on an old style class', |
@@ -43,7 +47,7 @@ MSGS = { |
{'maxversion': (3, 0)}), |
'W1001': ('Use of "property" on an old style class', |
'property-on-old-class', |
- 'Used when PyLint detect the use of the builtin "property" \ |
+ 'Used when Pylint detect the use of the builtin "property" \ |
on an old style class while this is relying on new style \ |
classes features.', |
{'maxversion': (3, 0)}), |
@@ -74,15 +78,21 @@ class NewStyleConflictChecker(BaseChecker): |
@check_messages('slots-on-old-class', 'old-style-class') |
def visit_class(self, node): |
- """check __slots__ usage |
+ """ Check __slots__ in old style classes and old |
+ style class definition. |
""" |
if '__slots__' in node and not node.newstyle: |
- self.add_message('slots-on-old-class', node=node) |
+ confidence = (INFERENCE if has_known_bases(node) |
+ else INFERENCE_FAILURE) |
+ self.add_message('slots-on-old-class', node=node, |
+ confidence=confidence) |
# The node type could be class, exception, metaclass, or |
# interface. Presumably, the non-class-type nodes would always |
# have an explicit base class anyway. |
- if not node.bases and node.type == 'class': |
- self.add_message('old-style-class', node=node) |
+ if not node.bases and node.type == 'class' and not node.metaclass(): |
+ # We use confidence HIGH here because this message should only ever |
+ # be emitted for classes at the root of the inheritance hierarchyself. |
+ self.add_message('old-style-class', node=node, confidence=HIGH) |
@check_messages('property-on-old-class') |
def visit_callfunc(self, node): |
@@ -91,9 +101,12 @@ class NewStyleConflictChecker(BaseChecker): |
if (isinstance(parent, astroid.Class) and |
not parent.newstyle and |
isinstance(node.func, astroid.Name)): |
+ confidence = (INFERENCE if has_known_bases(parent) |
+ else INFERENCE_FAILURE) |
name = node.func.name |
if name == 'property': |
- self.add_message('property-on-old-class', node=node) |
+ self.add_message('property-on-old-class', node=node, |
+ confidence=confidence) |
@check_messages('super-on-old-class', 'bad-super-call', 'missing-super-argument') |
def visit_function(self, node): |
@@ -103,6 +116,9 @@ class NewStyleConflictChecker(BaseChecker): |
return |
klass = node.parent.frame() |
for stmt in node.nodes_of_class(astroid.CallFunc): |
+ if node_frame_class(stmt) != node_frame_class(node): |
+ # Don't look down in other scopes. |
+ continue |
expr = stmt.func |
if not isinstance(expr, astroid.Getattr): |
continue |
@@ -111,9 +127,12 @@ class NewStyleConflictChecker(BaseChecker): |
if isinstance(call, astroid.CallFunc) and \ |
isinstance(call.func, astroid.Name) and \ |
call.func.name == 'super': |
+ confidence = (INFERENCE if has_known_bases(klass) |
+ else INFERENCE_FAILURE) |
if not klass.newstyle: |
# super should not be used on an old style class |
- self.add_message('super-on-old-class', node=node) |
+ self.add_message('super-on-old-class', node=node, |
+ confidence=confidence) |
else: |
# super first arg should be the class |
if not call.args and sys.version_info[0] == 3: |
@@ -121,13 +140,14 @@ class NewStyleConflictChecker(BaseChecker): |
continue |
try: |
- supcls = (call.args and call.args[0].infer().next() |
+ supcls = (call.args and next(call.args[0].infer()) |
or None) |
except astroid.InferenceError: |
continue |
if supcls is None: |
- self.add_message('missing-super-argument', node=call) |
+ self.add_message('missing-super-argument', node=call, |
+ confidence=confidence) |
continue |
if klass is not supcls: |
@@ -143,7 +163,8 @@ class NewStyleConflictChecker(BaseChecker): |
if name is not None: |
self.add_message('bad-super-call', |
node=call, |
- args=(name, )) |
+ args=(name, ), |
+ confidence=confidence) |
def register(linter): |