@@ -3882,6 +3882,27 @@ class CaseChangeOverSubstitution:
38823882 actual = self .get_suggestion (cls (), 'bluch' )
38833883 self .assertIn (suggestion , actual )
38843884
3885+ def test_getattr_suggestions_underscored (self ):
3886+ class A :
3887+ bluch = None
3888+
3889+ self .assertIn ("'bluch'" , self .get_suggestion (A (), 'blach' ))
3890+ self .assertIn ("'bluch'" , self .get_suggestion (A (), '_luch' ))
3891+ self .assertIn ("'bluch'" , self .get_suggestion (A (), '_bluch' ))
3892+
3893+ class B :
3894+ _bluch = None
3895+ def method (self , name ):
3896+ getattr (self , name )
3897+
3898+ self .assertIn ("'_bluch'" , self .get_suggestion (B (), '_blach' ))
3899+ self .assertIn ("'_bluch'" , self .get_suggestion (B (), '_luch' ))
3900+ self .assertNotIn ("'_bluch'" , self .get_suggestion (B (), 'bluch' ))
3901+
3902+ self .assertIn ("'_bluch'" , self .get_suggestion (partial (B ().method , '_blach' )))
3903+ self .assertIn ("'_bluch'" , self .get_suggestion (partial (B ().method , '_luch' )))
3904+ self .assertIn ("'_bluch'" , self .get_suggestion (partial (B ().method , 'bluch' )))
3905+
38853906 def test_getattr_suggestions_do_not_trigger_for_long_attributes (self ):
38863907 class A :
38873908 blech = None
@@ -4074,6 +4095,17 @@ def test_import_from_suggestions(self):
40744095 actual = self .get_import_from_suggestion (code , 'bluch' )
40754096 self .assertIn (suggestion , actual )
40764097
4098+ def test_import_from_suggestions_underscored (self ):
4099+ code = "bluch = None"
4100+ self .assertIn ("'bluch'" , self .get_import_from_suggestion (code , 'blach' ))
4101+ self .assertIn ("'bluch'" , self .get_import_from_suggestion (code , '_luch' ))
4102+ self .assertIn ("'bluch'" , self .get_import_from_suggestion (code , '_bluch' ))
4103+
4104+ code = "_bluch = None"
4105+ self .assertIn ("'_bluch'" , self .get_import_from_suggestion (code , '_blach' ))
4106+ self .assertIn ("'_bluch'" , self .get_import_from_suggestion (code , '_luch' ))
4107+ self .assertNotIn ("'_bluch'" , self .get_import_from_suggestion (code , 'bluch' ))
4108+
40774109 def test_import_from_suggestions_do_not_trigger_for_long_attributes (self ):
40784110 code = "blech = None"
40794111
0 commit comments