diff options
author | Nathaniel Manista <nathaniel@google.com> | 2017-03-07 01:43:46 -0800 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2017-03-07 11:43:46 +0200 |
commit | bd7d48e0ab74449a4767cc76fb1e42b2898c82ad (patch) | |
tree | c913969f3c94c8987c5e887e8e6a085f5a2159e5 | |
parent | 7df8caaa3e1995018417ac2fd87afd89be6945ba (diff) | |
download | pylint-git-bd7d48e0ab74449a4767cc76fb1e42b2898c82ad.tar.gz |
Add ignored_ and unused_ to unused-* inspections (#1357)
-rw-r--r-- | pylint/checkers/variables.py | 4 | ||||
-rw-r--r-- | pylint/test/functional/unused_argument.py | 7 | ||||
-rw-r--r-- | pylint/test/functional/unused_argument.txt | 2 | ||||
-rw-r--r-- | pylint/test/functional/unused_variable.py | 5 | ||||
-rw-r--r-- | pylint/test/functional/unused_variable.txt | 3 |
5 files changed, 17 insertions, 4 deletions
diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py index 3dde21881..7371af0b1 100644 --- a/pylint/checkers/variables.py +++ b/pylint/checkers/variables.py @@ -35,7 +35,7 @@ from pylint.checkers import utils SPECIAL_OBJ = re.compile("^_{2}[a-z]+_{2}$") FUTURE = '__future__' # regexp for ignored argument name -IGNORED_ARGUMENT_NAMES = re.compile('_.*') +IGNORED_ARGUMENT_NAMES = re.compile('_.*|^ignored_|^unused_') PY3K = sys.version_info >= (3, 0) @@ -337,7 +337,7 @@ class VariablesChecker(BaseChecker): 'help' : 'Tells whether we should check for unused import in ' '__init__ files.'}), ("dummy-variables-rgx", - {'default': ('_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy'), + {'default': '_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_', 'type' :'regexp', 'metavar' : '<regexp>', 'help' : 'A regular expression matching the name of dummy ' 'variables (i.e. expectedly not used).'}), diff --git a/pylint/test/functional/unused_argument.py b/pylint/test/functional/unused_argument.py index bfaf7d2c9..06cc69656 100644 --- a/pylint/test/functional/unused_argument.py +++ b/pylint/test/functional/unused_argument.py @@ -4,6 +4,13 @@ def test_unused(first, second, _not_used): # [unused-argument, unused-argument] pass +def test_prefixed_with_ignored(first, ignored_second): + first() + + +def test_prefixed_with_unused(first, unused_second): + first() + # for Sub.inherited, only the warning for "aay" is desired. # The warnings for "aab" and "aac" are most likely false positives though, # because there could be another subclass that overrides the same method and does diff --git a/pylint/test/functional/unused_argument.txt b/pylint/test/functional/unused_argument.txt index dc787ee67..d5834389f 100644 --- a/pylint/test/functional/unused_argument.txt +++ b/pylint/test/functional/unused_argument.txt @@ -1,3 +1,3 @@ unused-argument:3:test_unused:Unused argument 'first' unused-argument:3:test_unused:Unused argument 'second' -unused-argument:25:Sub.newmethod:Unused argument 'aay':INFERENCE
\ No newline at end of file +unused-argument:32:Sub.newmethod:Unused argument 'aay':INFERENCE diff --git a/pylint/test/functional/unused_variable.py b/pylint/test/functional/unused_variable.py index 48a46b891..e8e752af8 100644 --- a/pylint/test/functional/unused_variable.py +++ b/pylint/test/functional/unused_variable.py @@ -15,3 +15,8 @@ def test_unused_with_prepended_underscore(): _a_ = 42 # [unused-variable] __a__ = 24 # [unused-variable] __never_used = 42 + +def test_local_field_prefixed_with_unused_or_ignored(): + flagged_local_field = 42 # [unused-variable] + unused_local_field = 42 + ignored_local_field = 42 diff --git a/pylint/test/functional/unused_variable.txt b/pylint/test/functional/unused_variable.txt index ddd5a3994..0e659ba5e 100644 --- a/pylint/test/functional/unused_variable.txt +++ b/pylint/test/functional/unused_variable.txt @@ -2,4 +2,5 @@ unused-variable:4:test_regression_737:Unused variable 'xml' unused-variable:7:test_regression_923:Unused variable 'unittest.case' unused-variable:8:test_regression_923:Unused variable 'sql' unused-variable:15:test_unused_with_prepended_underscore:Unused variable '_a_' -unused-variable:16:test_unused_with_prepended_underscore:Unused variable '__a__'
\ No newline at end of file +unused-variable:16:test_unused_with_prepended_underscore:Unused variable '__a__' +unused-variable:20:test_local_field_prefixed_with_unused_or_ignored:Unused variable 'flagged_local_field' |