@@ -36,12 +36,33 @@ def normal(self):
3636 super (MyClass , self ).f () # can use super()
3737 super ().f ()
3838
39+ def different_class (self ):
40+ super (BaseClass , self ).f () # CANNOT use super()
41+
3942 def different_argument (self , other ):
4043 super (MyClass , other ).f () # CANNOT use super()
4144
4245 def comprehension_scope (self ):
4346 [super (MyClass , self ).f () for x in [1 ]] # CANNOT use super()
4447
48+ def comprehension_scope_set (self ):
49+ {super (MyClass , self ).f () for x in [1 ]} # CANNOT use super()
50+
51+ def comprehension_scope_generator (self ):
52+ (super (MyClass , self ).f () for x in [1 ]) # CANNOT use super()
53+
54+ def comprehension_scope_dict (self ):
55+ {True : super (MyClass , self ).f () for x in [1 ]} # CANNOT use super()
56+
57+ def nested_comprehension_scope (self ):
58+ [
59+ (
60+ [x for x in [1 ]],
61+ super (MyClass , self ).f (),
62+ )
63+ for _ in [1 ]
64+ ] # CANNOT use super()
65+
4566 def inner_functions (self ):
4667 def outer_argument ():
4768 super (MyClass , self ).f () # CANNOT use super()
@@ -53,6 +74,10 @@ def inner_argument(self):
5374 outer_argument ()
5475 inner_argument (self )
5576
77+ def lambda_closure (self ):
78+ g = lambda : super (MyClass , self ).f () # CANNOT use super()
79+ g ()
80+
5681 def inner_class (self ):
5782 class InnerClass :
5883 super (MyClass , self ).f () # CANNOT use super()
@@ -64,7 +89,6 @@ def method(inner_self):
6489
6590 defined_outside = defined_outside
6691
67-
6892from dataclasses import dataclass
6993
7094
@@ -318,6 +342,23 @@ def __init__(self, foo):
318342 super (Outer .Inner , self ).__init__ (foo ) # UP008: matches enclosing class chain
319343
320344
345+ # See: https://github.com/astral-sh/ruff/issues/24001
346+ # Bare and partially qualified class names should not match nested classes.
347+ class CommonNesting :
348+ class C (Base ):
349+ def __init__ (self , foo ):
350+ # TODO(charlie): false positive until nested class matching is fixed.
351+ super (C , self ).__init__ (foo ) # Should NOT trigger UP008
352+
353+
354+ class HigherLevelsOfNesting :
355+ class Inner :
356+ class C (Base ):
357+ def __init__ (self , foo ):
358+ # TODO(charlie): false positive until nested class matching is fixed.
359+ super (Inner .C , self ).__init__ (foo ) # Should NOT trigger UP008
360+
361+
321362# super() first arg is an attribute that only matches on the last segment,
322363# but refers to a different class (Outer.Inner, not __class__ which is Inner).
323364class Inner (Outer .Inner ):
@@ -343,3 +384,36 @@ class Inner(Base):
343384 def __init__ (self , foo ):
344385 super (Wrong .Inner , self ).__init__ (foo ) # Should NOT trigger UP008
345386
387+
388+ class Whitespace (BaseClass ):
389+ def f (self ):
390+ super (Whitespace , self ).f () # can use super()
391+
392+
393+ def function_local ():
394+ class LocalOuter :
395+ class LocalInner (BaseClass ):
396+ def f (self ):
397+ super (LocalOuter .LocalInner , self ).f () # can use super()
398+
399+
400+ class LambdaMethod (BaseClass ):
401+ # TODO(charlie): class-body lambda rewrite is still missed.
402+ f = lambda self : super (LambdaMethod , self ).f () # can use super()
403+
404+
405+ class ClassMethod (BaseClass ):
406+ @classmethod
407+ def f (cls ):
408+ super (ClassMethod , cls ).f () # can use super()
409+
410+
411+ class AsyncMethod (BaseClass ):
412+ async def f (self ):
413+ super (AsyncMethod , self ).f () # can use super()
414+
415+
416+ class OuterWithWhitespace :
417+ class Inner (BaseClass ):
418+ def f (self ):
419+ super (OuterWithWhitespace .Inner , self ).f () # can use super()
0 commit comments