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 @@ -1791,6 +1791,20 @@ def _():
17911791 pass
17921792 ''' )
17931793
1794+ def test_usedDecoratedFunction (self ):
1795+ """
1796+ Don't warn when the function is decorated because decorators can do
1797+ anything, like copy it into global state.
1798+ """
1799+ self .flakes ('''
1800+ from somewhere import decorator
1801+
1802+ def a():
1803+ @decorator
1804+ def b():
1805+ pass
1806+ ''' )
1807+
17941808
17951809class TestUnusedClass (TestCase ):
17961810 """
@@ -1818,6 +1832,20 @@ class _:
18181832 pass
18191833 ''' )
18201834
1835+ def test_usedDecoratedClass (self ):
1836+ """
1837+ Don't warn when the class is decorated because decorators can do
1838+ anything, like copy it into global state.
1839+ """
1840+ self .flakes ('''
1841+ from somewhere import decorator
1842+
1843+ def a():
1844+ @decorator
1845+ class B:
1846+ pass
1847+ ''' )
1848+
18211849
18221850class TestStringFormatting (TestCase ):
18231851
You can’t perform that action at this time.
0 commit comments