File tree 2 files changed +36
-2
lines changed
2 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -1845,9 +1845,15 @@ def checkUnusedBindings():
1845
1845
for name , binding in self .scope .unusedBindings ():
1846
1846
if isinstance (binding , Assignment ):
1847
1847
self .report (messages .UnusedVariable , binding .source , name )
1848
- elif isinstance (binding , ClassDefinition ):
1848
+ elif (
1849
+ isinstance (binding , ClassDefinition )
1850
+ and not binding .source .decorator_list
1851
+ ):
1849
1852
self .report (messages .UnusedClass , binding .source , name )
1850
- elif isinstance (binding , FunctionDefinition ):
1853
+ elif (
1854
+ isinstance (binding , FunctionDefinition )
1855
+ and not binding .source .decorator_list
1856
+ ):
1851
1857
self .report (messages .UnusedFunction , binding .source , name )
1852
1858
self .deferAssignment (checkUnusedBindings )
1853
1859
Original file line number Diff line number Diff line change @@ -1793,6 +1793,20 @@ def _():
1793
1793
pass
1794
1794
''' )
1795
1795
1796
+ def test_usedDecoratedFunction (self ):
1797
+ """
1798
+ Don't warn when the function is decorated because decorators can do
1799
+ anything, like copy it into global state.
1800
+ """
1801
+ self .flakes ('''
1802
+ from somewhere import decorator
1803
+
1804
+ def a():
1805
+ @decorator
1806
+ def b():
1807
+ pass
1808
+ ''' )
1809
+
1796
1810
1797
1811
class TestUnusedClass (TestCase ):
1798
1812
"""
@@ -1820,6 +1834,20 @@ class _:
1820
1834
pass
1821
1835
''' )
1822
1836
1837
+ def test_usedDecoratedClass (self ):
1838
+ """
1839
+ Don't warn when the class is decorated because decorators can do
1840
+ anything, like copy it into global state.
1841
+ """
1842
+ self .flakes ('''
1843
+ from somewhere import decorator
1844
+
1845
+ def a():
1846
+ @decorator
1847
+ class B:
1848
+ pass
1849
+ ''' )
1850
+
1823
1851
1824
1852
class TestStringFormatting (TestCase ):
1825
1853
You can’t perform that action at this time.
0 commit comments