1. Jendrik Seipp
  2. vulture

Commits

Jendrik Seipp  committed 7f1b513

Ignore unused variables starting with an underscore (_x, _unused, _)

  • Participants
  • Parent commits a02ec9e
  • Branches default

Comments (0)

Files changed (3)

File NEWS.txt

View file
 News
 ====
 
+0.4 ()
+------
+* Ignore unused variables starting with an underscore (_x, _unused, _)
+
 
 0.3 (2012-03-19)
 ----------------

File tests/test_scavenging.py

View file
     assert v.unused_vars == []
 
 
+def test_unused_var1():
+    v = Vulture(verbose=True)
+    v.scan("_a = 1\n__b = 2\n__c__ = 3")
+    assert v.defined_vars == []
+    assert sorted(v.used_vars) == []
+    assert v.unused_vars == []
+
+
 def test_prop1():
     v = Vulture(verbose=True)
     v.scan("""\

File wake.py

View file
                 self.log('used_vars <-', node.id)
                 self.used_vars.append(node.id)
             elif isinstance(node.ctx, ast.Store):
-                if not (node.id.startswith('__') and node.id.endswith('__')):
+                # Ignore _x (pylint convention), __x, __x__ (special method).
+                if not node.id.startswith('_'):
                     item = self._get_item(node, 'variable')
                     self.log('defined_vars <-', item)
                     self.defined_vars.append(item)