diff options
author | Sylvain Thénault <sylvain.thenault@logilab.fr> | 2012-09-20 06:43:07 +0200 |
---|---|---|
committer | Sylvain Thénault <sylvain.thenault@logilab.fr> | 2012-09-20 06:43:07 +0200 |
commit | 163c4466948197ee2dfa6eaf2e7d7aa3e34a7cba (patch) | |
tree | b03594bdd14345977ab81a25a1d23dd6b1c9f8fe | |
parent | 4e6fa0d70949012614ea7adcf9a3ca0d43006895 (diff) | |
download | pylint-git-163c4466948197ee2dfa6eaf2e7d7aa3e34a7cba.tar.gz |
Add name type in C0103 message
-rw-r--r-- | checkers/base.py | 9 | ||||
-rw-r--r-- | test/messages/func_w0110.txt | 2 | ||||
-rw-r--r-- | test/messages/func_w0133.txt | 16 | ||||
-rw-r--r-- | test/messages/func_w0623.txt | 6 |
4 files changed, 18 insertions, 15 deletions
diff --git a/checkers/base.py b/checkers/base.py index 69b0a2bed..3cd592267 100644 --- a/checkers/base.py +++ b/checkers/base.py @@ -582,7 +582,7 @@ class NameChecker(_BasicChecker): 'blacklisted-name', 'Used when the name is listed in the black list (unauthorized \ names).'), - 'C0103': ('Invalid name "%s" (should match %s)', + 'C0103': ('Invalid name "%s" for type %s (should match %s)', 'invalid-name', 'Used when the name doesn\'t match the regular expression \ associated to its type (constant, variable, class...).'), @@ -716,7 +716,6 @@ class NameChecker(_BasicChecker): clobbering, _ = clobber_in_except(node) if clobbering: return - if name in self.config.good_names: return if name in self.config.bad_names: @@ -725,7 +724,11 @@ class NameChecker(_BasicChecker): return regexp = getattr(self.config, node_type + '_rgx') if regexp.match(name) is None: - self.add_message('C0103', node=node, args=(name, regexp.pattern)) + type_label = {'inlinedvar': 'inlined variable', + 'const': 'constant', + 'attr': 'attribute', + }.get(node_type, node_type) + self.add_message('C0103', node=node, args=(name, type_label, regexp.pattern)) self.stats['badname_' + node_type] += 1 diff --git a/test/messages/func_w0110.txt b/test/messages/func_w0110.txt index 28f48aab0..d8d5ef892 100644 --- a/test/messages/func_w0110.txt +++ b/test/messages/func_w0110.txt @@ -1 +1 @@ -C: 8:a: Invalid name "a" (should match [a-z_][a-z0-9_]{2,30}$) +C: 8:a: Invalid name "a" for type function (should match [a-z_][a-z0-9_]{2,30}$) diff --git a/test/messages/func_w0133.txt b/test/messages/func_w0133.txt index 1ba2ad6c1..48c768d49 100644 --- a/test/messages/func_w0133.txt +++ b/test/messages/func_w0133.txt @@ -1,9 +1,9 @@ -C: 8:Run.B: Invalid name "B" (should match [A-Z_][a-zA-Z0-9]+$) -C: 12:Run: Invalid name "bBb" (should match [a-z_][a-z0-9_]{2,30}$) -C: 26:HOHOHOHO: Invalid name "HOHOHOHO" (should match [a-z_][a-z0-9_]{2,30}$) -C: 28:HOHOHOHO: Invalid name "HIHIHI" (should match [a-z_][a-z0-9_]{2,30}$) -C: 31:xyz: Invalid name "xyz" (should match [A-Z_][a-zA-Z0-9]+$) -C: 36:xyz.Youplapoum: Invalid name "Youplapoum" (should match [a-z_][a-z0-9_]{2,30}$) -C: 46: Invalid name "benpasceluila" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$) -C: 52:Correct.__init__: Invalid name "_Ca_va_Pas" (should match [a-z_][a-z0-9_]{2,30}$) +C: 8:Run.B: Invalid name "B" for type class (should match [A-Z_][a-zA-Z0-9]+$) +C: 12:Run: Invalid name "bBb" for type variable (should match [a-z_][a-z0-9_]{2,30}$) +C: 26:HOHOHOHO: Invalid name "HOHOHOHO" for type function (should match [a-z_][a-z0-9_]{2,30}$) +C: 28:HOHOHOHO: Invalid name "HIHIHI" for type variable (should match [a-z_][a-z0-9_]{2,30}$) +C: 31:xyz: Invalid name "xyz" for type class (should match [A-Z_][a-zA-Z0-9]+$) +C: 36:xyz.Youplapoum: Invalid name "Youplapoum" for type method (should match [a-z_][a-z0-9_]{2,30}$) +C: 46: Invalid name "benpasceluila" for type constant (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$) +C: 52:Correct.__init__: Invalid name "_Ca_va_Pas" for type attribute (should match [a-z_][a-z0-9_]{2,30}$) W: 8:Run.B: Unused variable 'B' diff --git a/test/messages/func_w0623.txt b/test/messages/func_w0623.txt index f17fedb4b..7e2cb1f99 100644 --- a/test/messages/func_w0623.txt +++ b/test/messages/func_w0623.txt @@ -1,6 +1,6 @@ -C: 28:some_function: Invalid name "FOO" (should match [a-z_][a-z0-9_]{2,30}$) -C: 41: Invalid name "exc3" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$) -C: 55: Invalid name "OOPS" (should match [a-z_][a-z0-9_]{2,30}$) +C: 28:some_function: Invalid name "FOO" for type variable (should match [a-z_][a-z0-9_]{2,30}$) +C: 41: Invalid name "exc3" for type constant (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$) +C: 55: Invalid name "OOPS" for type variable (should match [a-z_][a-z0-9_]{2,30}$) W: 18:some_function: Redefining name 'RuntimeError' from object 'exceptions' in exception handler W: 20:some_function: Redefining name 'OSError' from builtins in exception handler W: 20:some_function: Unused variable 'OSError' |