File tree Expand file tree Collapse file tree 2 files changed +36
-2
lines changed
Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -1845,9 +1845,15 @@ def checkUnusedBindings():
18451845 for name , binding in self .scope .unusedBindings ():
18461846 if isinstance (binding , Assignment ):
18471847 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+ ):
18491852 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+ ):
18511857 self .report (messages .UnusedFunction , binding .source , name )
18521858 self .deferAssignment (checkUnusedBindings )
18531859
Original file line number Diff line number Diff line change @@ -1793,6 +1793,20 @@ def _():
17931793 pass
17941794 ''' )
17951795
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+
17961810
17971811class TestUnusedClass (TestCase ):
17981812 """
@@ -1820,6 +1834,20 @@ class _:
18201834 pass
18211835 ''' )
18221836
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+
18231851
18241852class TestStringFormatting (TestCase ):
18251853
You can’t perform that action at this time.
0 commit comments