diff options
author | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2010-03-23 08:49:23 +0100 |
---|---|---|
committer | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2010-03-23 08:49:23 +0100 |
commit | 655c0fe06f6c6691315a6051e30b6e06abe19cf7 (patch) | |
tree | 7395e275260f8d246d60b049d7619b523749c79a | |
parent | 14f35a56b9bc2cef9d612d7437112765bc619eda (diff) | |
download | pylint-655c0fe06f6c6691315a6051e30b6e06abe19cf7.tar.gz |
nikola kramaric fix #5975, Abstract intermediate class not recognized as such
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | checkers/classes.py | 14 | ||||
-rw-r--r-- | test/input/func_w0223.py | 9 | ||||
-rw-r--r-- | test/messages/func_w0223.txt | 4 |
4 files changed, 28 insertions, 1 deletions
@@ -10,6 +10,8 @@ ChangeLog for PyLint * fix #20991, class scope definitions ignored in a genexpr + * fix #5975, Abstract intermediate class not recognized as such + * fix #5977, yield and return statement have their own counters, no more R0911 (Too many return statements) when a function have many yield stamtements diff --git a/checkers/classes.py b/checkers/classes.py index 6494e27..b722742 100644 --- a/checkers/classes.py +++ b/checkers/classes.py @@ -24,6 +24,17 @@ from pylint.interfaces import IASTNGChecker from pylint.checkers import BaseChecker from pylint.checkers.utils import PYMETHODS, overrides_a_method +def class_is_abstract(node): + """return true if the given class node should be considered as an abstract + class + """ + for method in node.methods(): + if method.parent.frame() is node: + if method.is_abstract(pass_is_abstract=False): + return True + return False + + MSGS = { 'F0202': ('Unable to check methods signature (%s / %s)', 'Used when PyLint has been unable to check methods signature \ @@ -369,6 +380,9 @@ instance attributes.'} """check that the given class node implements abstract methods from base classes """ + # check if this class abstract + if class_is_abstract(node): + return for method in node.methods(): owner = method.parent.frame() if owner is node: diff --git a/test/input/func_w0223.py b/test/input/func_w0223.py index e1e81bf..0682172 100644 --- a/test/input/func_w0223.py +++ b/test/input/func_w0223.py @@ -19,6 +19,15 @@ class Abstract: def __init__(self): pass +class AbstractB(Abstract): + """abstract class + this class is checking that it does not output an error msg for + unimplemeted methods in abstract classes + """ + def cccc(self): + """should be overridden in concrete class""" + raise NotImplementedError() + class Concret(Abstract): """concret class""" diff --git a/test/messages/func_w0223.txt b/test/messages/func_w0223.txt index fc735da..943cf03 100644 --- a/test/messages/func_w0223.txt +++ b/test/messages/func_w0223.txt @@ -1,2 +1,4 @@ -W: 22:Concret: Method 'bbbb' is abstract in class 'Abstract' but is not overridden +R: 22:AbstractB: Abstract class not referenced +W: 31:Concret: Method 'bbbb' is abstract in class 'Abstract' but is not overridden + |