File tree Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -348,6 +348,10 @@ def checkDeadScopes(self):
348
348
which were imported but unused.
349
349
"""
350
350
for scope in self .deadScopes :
351
+ # imports in classes are public members
352
+ if isinstance (scope , ClassScope ):
353
+ continue
354
+
351
355
if isinstance (scope .get ('__all__' ), ExportBinding ):
352
356
all_names = set (scope ['__all__' ].names )
353
357
if not scope .importStarred and \
Original file line number Diff line number Diff line change @@ -236,6 +236,22 @@ class bar:
236
236
print(fu)
237
237
''' )
238
238
239
+ def test_importInClass (self ):
240
+ """
241
+ Test that import within class is a locally scoped attribute.
242
+ """
243
+ self .flakes ('''
244
+ class bar:
245
+ import fu
246
+ ''' )
247
+
248
+ self .flakes ('''
249
+ class bar:
250
+ import fu
251
+
252
+ fu
253
+ ''' , m .UndefinedName )
254
+
239
255
def test_usedInFunction (self ):
240
256
self .flakes ('''
241
257
import fu
@@ -570,7 +586,7 @@ class bar:
570
586
import fu
571
587
def fun(self):
572
588
fu
573
- ''' , m .UnusedImport , m . UndefinedName )
589
+ ''' , m .UndefinedName )
574
590
575
591
def test_nestedFunctionsNestScope (self ):
576
592
self .flakes ('''
@@ -689,7 +705,6 @@ def test_importingForImportError(self):
689
705
pass
690
706
''' )
691
707
692
- @skip ("todo: requires evaluating attribute access" )
693
708
def test_importedInClass (self ):
694
709
"""Imports in class scope can be used through self."""
695
710
self .flakes ('''
@@ -760,12 +775,11 @@ def foo():
760
775
761
776
def test_ignoredInClass (self ):
762
777
"""
763
- An C{__all__} definition does not suppress unused import warnings in a
764
- class scope.
778
+ An C{__all__} definition in a class does not suppress unused import warnings.
765
779
"""
766
780
self .flakes ('''
781
+ import bar
767
782
class foo:
768
- import bar
769
783
__all__ = ["bar"]
770
784
''' , m .UnusedImport )
771
785
You can’t perform that action at this time.
0 commit comments