@@ -1314,6 +1314,29 @@ def test_attributes(self):
1314
1314
self .assertEqual (exc .name , 'carry' )
1315
1315
self .assertIs (exc .obj , sentinel )
1316
1316
1317
+ def test_getattr_has_name_and_obj (self ):
1318
+ class A :
1319
+ blech = None
1320
+
1321
+ obj = A ()
1322
+ try :
1323
+ obj .bluch
1324
+ except AttributeError as exc :
1325
+ self .assertEqual ("bluch" , exc .name )
1326
+ self .assertEqual (obj , exc .obj )
1327
+
1328
+ def test_getattr_has_name_and_obj_for_method (self ):
1329
+ class A :
1330
+ def blech (self ):
1331
+ return
1332
+
1333
+ obj = A ()
1334
+ try :
1335
+ obj .bluch ()
1336
+ except AttributeError as exc :
1337
+ self .assertEqual ("bluch" , exc .name )
1338
+ self .assertEqual (obj , exc .obj )
1339
+
1317
1340
def test_getattr_suggestions (self ):
1318
1341
class A :
1319
1342
blech = None
@@ -1324,7 +1347,7 @@ class A:
1324
1347
with support .captured_stderr () as err :
1325
1348
sys .__excepthook__ (* sys .exc_info ())
1326
1349
1327
- # self.assertIn("blech", err.getvalue())
1350
+ self .assertIn ("blech" , err .getvalue ())
1328
1351
1329
1352
def test_getattr_suggestions_do_not_trigger_for_long_attributes (self ):
1330
1353
class A :
@@ -1391,13 +1414,24 @@ class A:
1391
1414
def __getattr__ (self , attr ):
1392
1415
raise AttributeError (NonStringifyClass ())
1393
1416
1394
- try :
1395
- A ().bluch
1396
- except AttributeError as exc :
1397
- with support .captured_stderr () as err :
1398
- sys .__excepthook__ (* sys .exc_info ())
1417
+ class B :
1418
+ blech = None
1419
+ def __getattr__ (self , attr ):
1420
+ raise AttributeError ("Error" , 23 )
1399
1421
1400
- self .assertIn ("blech" , err .getvalue ())
1422
+ class C :
1423
+ blech = None
1424
+ def __getattr__ (self , attr ):
1425
+ raise AttributeError (23 )
1426
+
1427
+ for cls in [A , B , C ]:
1428
+ try :
1429
+ cls ().bluch
1430
+ except AttributeError as exc :
1431
+ with support .captured_stderr () as err :
1432
+ sys .__excepthook__ (* sys .exc_info ())
1433
+
1434
+ self .assertNotIn ("blech" , err .getvalue ())
1401
1435
1402
1436
1403
1437
class ImportErrorTests (unittest .TestCase ):
0 commit comments