@@ -4020,7 +4020,8 @@ def test_dont_swallow_subexceptions_of_falsey_exceptiongroup(self):
40204020
40214021global_for_suggestions = None
40224022
4023- class SuggestionFormattingTestBaseParent :
4023+
4024+ class SuggestionFormattingTestMixin :
40244025 def get_suggestion (self , obj , attr_name = None ):
40254026 if attr_name is not None :
40264027 def callable ():
@@ -4033,10 +4034,12 @@ def callable():
40334034 )
40344035 return result_lines [0 ]
40354036
4036- class BaseSuggestionTests (SuggestionFormattingTestBaseParent ):
4037+
4038+ class BaseSuggestionTests (SuggestionFormattingTestMixin ):
40374039 """
40384040 Subclasses need to implement the get_suggestion method.
40394041 """
4042+
40404043 def test_suggestions (self ):
40414044 class Substitution :
40424045 noise = more_noise = a = bc = None
@@ -4077,50 +4080,40 @@ class CaseChangeOverSubstitution:
40774080 (EliminationOverAddition , "'bluc'?" ),
40784081 (CaseChangeOverSubstitution , "'BLuch'?" ),
40794082 ]:
4080- obj = cls ()
4081- actual = self .get_suggestion (obj , 'bluch' )
4083+ actual = self .get_suggestion (cls (), 'bluch' )
40824084 self .assertIn (suggestion , actual )
40834085
40844086 def test_suggestions_underscored (self ):
40854087 class A :
40864088 bluch = None
40874089
4088- obj = A ()
4089- self .assertIn ("'bluch'" , self .get_suggestion (obj , 'blach' ))
4090- self .assertIn ("'bluch'" , self .get_suggestion (obj , '_luch' ))
4091- self .assertIn ("'bluch'" , self .get_suggestion (obj , '_bluch' ))
4090+ self .assertIn ("'bluch'" , self .get_suggestion (A (), 'blach' ))
4091+ self .assertIn ("'bluch'" , self .get_suggestion (A (), '_luch' ))
4092+ self .assertIn ("'bluch'" , self .get_suggestion (A (), '_bluch' ))
40924093
40934094 class B :
40944095 _bluch = None
40954096 def method (self , name ):
40964097 getattr (self , name )
40974098
4098- obj = B ()
4099- self .assertIn ("'_bluch'" , self .get_suggestion (obj , '_blach' ))
4100- self .assertIn ("'_bluch'" , self .get_suggestion (obj , '_luch' ))
4101- self .assertNotIn ("'_bluch'" , self .get_suggestion (obj , 'bluch' ))
4102-
4103- if hasattr (self , 'test_with_method_call' ):
4104- self .assertIn ("'_bluch'" , self .get_suggestion (partial (obj .method , '_blach' )))
4105- self .assertIn ("'_bluch'" , self .get_suggestion (partial (obj .method , '_luch' )))
4106- self .assertIn ("'_bluch'" , self .get_suggestion (partial (obj .method , 'bluch' )))
4099+ self .assertIn ("'_bluch'" , self .get_suggestion (B (), '_blach' ))
4100+ self .assertIn ("'_bluch'" , self .get_suggestion (B (), '_luch' ))
4101+ self .assertNotIn ("'_bluch'" , self .get_suggestion (B (), 'bluch' ))
41074102
41084103 def test_do_not_trigger_for_long_attributes (self ):
41094104 class A :
41104105 blech = None
41114106
4112- obj = A ()
4113- actual = self .get_suggestion (obj , 'somethingverywrong' )
4107+ actual = self .get_suggestion (A (), 'somethingverywrong' )
41144108 self .assertNotIn ("blech" , actual )
41154109
41164110 def test_do_not_trigger_for_small_names (self ):
41174111 class MyClass :
41184112 vvv = mom = w = id = pytho = None
41194113
4120- obj = MyClass ()
41214114 for name in ("b" , "v" , "m" , "py" ):
41224115 with self .subTest (name = name ):
4123- actual = self .get_suggestion (obj , name )
4116+ actual = self .get_suggestion (MyClass () , name )
41244117 self .assertNotIn ("Did you mean" , actual )
41254118 self .assertNotIn ("'vvv" , actual )
41264119 self .assertNotIn ("'mom'" , actual )
@@ -4136,10 +4129,10 @@ class A:
41364129 for index in range (2000 ):
41374130 setattr (A , f"index_{ index } " , None )
41384131
4139- obj = A ()
4140- actual = self .get_suggestion (obj , 'bluch' )
4132+ actual = self .get_suggestion (A (), 'bluch' )
41414133 self .assertNotIn ("blech" , actual )
41424134
4135+
41434136class GetattrSuggestionTests (BaseSuggestionTests ):
41444137 def get_suggestion (self , obj , attr_name = None ):
41454138 if attr_name is not None :
@@ -4153,11 +4146,6 @@ def callable():
41534146 )
41544147 return result_lines [0 ]
41554148
4156- def test_with_method_call (self ):
4157- # This is a placeholder method to make
4158- # hasattr(self, 'test_with_method_call') return True
4159- pass
4160-
41614149 def test_suggestions_no_args (self ):
41624150 class A :
41634151 blech = None
@@ -4206,6 +4194,17 @@ def __dir__(self):
42064194 actual = self .get_suggestion (A (), 'blech' )
42074195 self .assertNotIn ("Did you mean" , actual )
42084196
4197+ def test_suggestions_with_method_call (self ):
4198+ class B :
4199+ _bluch = None
4200+ def method (self , name ):
4201+ getattr (self , name )
4202+
4203+ self .assertIn ("'_bluch'" , self .get_suggestion (partial (B ().method , '_blach' )))
4204+ self .assertIn ("'_bluch'" , self .get_suggestion (partial (B ().method , '_luch' )))
4205+ self .assertIn ("'_bluch'" , self .get_suggestion (partial (B ().method , 'bluch' )))
4206+
4207+
42094208class DelattrSuggestionTests (BaseSuggestionTests ):
42104209 def get_suggestion (self , obj , attr_name ):
42114210 def callable ():
@@ -4216,7 +4215,8 @@ def callable():
42164215 )
42174216 return result_lines [0 ]
42184217
4219- class SuggestionFormattingTestBase (SuggestionFormattingTestBaseParent ):
4218+
4219+ class SuggestionFormattingTestBase (SuggestionFormattingTestMixin ):
42204220 def test_attribute_error_with_failing_dict (self ):
42214221 class T :
42224222 bluch = 1
0 commit comments