@@ -417,45 +417,45 @@ def testAttributes(self):
417
417
# test that exception attributes are happy
418
418
419
419
exceptionList = [
420
- (BaseException , (), {'args' : ()}),
421
- (BaseException , (1 , ), {'args' : (1 ,)}),
422
- (BaseException , ('foo' ,),
420
+ (BaseException , (), {}, { 'args' : ()}),
421
+ (BaseException , (1 , ), {}, { 'args' : (1 ,)}),
422
+ (BaseException , ('foo' ,), {},
423
423
{'args' : ('foo' ,)}),
424
- (BaseException , ('foo' , 1 ),
424
+ (BaseException , ('foo' , 1 ), {},
425
425
{'args' : ('foo' , 1 )}),
426
- (SystemExit , ('foo' ,),
426
+ (SystemExit , ('foo' ,), {},
427
427
{'args' : ('foo' ,), 'code' : 'foo' }),
428
- (OSError , ('foo' ,),
428
+ (OSError , ('foo' ,), {},
429
429
{'args' : ('foo' ,), 'filename' : None , 'filename2' : None ,
430
430
'errno' : None , 'strerror' : None }),
431
- (OSError , ('foo' , 'bar' ),
431
+ (OSError , ('foo' , 'bar' ), {},
432
432
{'args' : ('foo' , 'bar' ),
433
433
'filename' : None , 'filename2' : None ,
434
434
'errno' : 'foo' , 'strerror' : 'bar' }),
435
- (OSError , ('foo' , 'bar' , 'baz' ),
435
+ (OSError , ('foo' , 'bar' , 'baz' ), {},
436
436
{'args' : ('foo' , 'bar' ),
437
437
'filename' : 'baz' , 'filename2' : None ,
438
438
'errno' : 'foo' , 'strerror' : 'bar' }),
439
- (OSError , ('foo' , 'bar' , 'baz' , None , 'quux' ),
439
+ (OSError , ('foo' , 'bar' , 'baz' , None , 'quux' ), {},
440
440
{'args' : ('foo' , 'bar' ), 'filename' : 'baz' , 'filename2' : 'quux' }),
441
- (OSError , ('errnoStr' , 'strErrorStr' , 'filenameStr' ),
441
+ (OSError , ('errnoStr' , 'strErrorStr' , 'filenameStr' ), {},
442
442
{'args' : ('errnoStr' , 'strErrorStr' ),
443
443
'strerror' : 'strErrorStr' , 'errno' : 'errnoStr' ,
444
444
'filename' : 'filenameStr' }),
445
- (OSError , (1 , 'strErrorStr' , 'filenameStr' ),
445
+ (OSError , (1 , 'strErrorStr' , 'filenameStr' ), {},
446
446
{'args' : (1 , 'strErrorStr' ), 'errno' : 1 ,
447
447
'strerror' : 'strErrorStr' ,
448
448
'filename' : 'filenameStr' , 'filename2' : None }),
449
- (SyntaxError , (), {'msg' : None , 'text' : None ,
449
+ (SyntaxError , (), {}, { 'msg' : None , 'text' : None ,
450
450
'filename' : None , 'lineno' : None , 'offset' : None ,
451
451
'end_offset' : None , 'print_file_and_line' : None }),
452
- (SyntaxError , ('msgStr' ,),
452
+ (SyntaxError , ('msgStr' ,), {},
453
453
{'args' : ('msgStr' ,), 'text' : None ,
454
454
'print_file_and_line' : None , 'msg' : 'msgStr' ,
455
455
'filename' : None , 'lineno' : None , 'offset' : None ,
456
456
'end_offset' : None }),
457
457
(SyntaxError , ('msgStr' , ('filenameStr' , 'linenoStr' , 'offsetStr' ,
458
- 'textStr' , 'endLinenoStr' , 'endOffsetStr' )),
458
+ 'textStr' , 'endLinenoStr' , 'endOffsetStr' )), {},
459
459
{'offset' : 'offsetStr' , 'text' : 'textStr' ,
460
460
'args' : ('msgStr' , ('filenameStr' , 'linenoStr' ,
461
461
'offsetStr' , 'textStr' ,
@@ -465,46 +465,48 @@ def testAttributes(self):
465
465
'end_lineno' : 'endLinenoStr' , 'end_offset' : 'endOffsetStr' }),
466
466
(SyntaxError , ('msgStr' , 'filenameStr' , 'linenoStr' , 'offsetStr' ,
467
467
'textStr' , 'endLinenoStr' , 'endOffsetStr' ,
468
- 'print_file_and_lineStr' ),
468
+ 'print_file_and_lineStr' ), {},
469
469
{'text' : None ,
470
470
'args' : ('msgStr' , 'filenameStr' , 'linenoStr' , 'offsetStr' ,
471
471
'textStr' , 'endLinenoStr' , 'endOffsetStr' ,
472
472
'print_file_and_lineStr' ),
473
473
'print_file_and_line' : None , 'msg' : 'msgStr' ,
474
474
'filename' : None , 'lineno' : None , 'offset' : None ,
475
475
'end_lineno' : None , 'end_offset' : None }),
476
- (UnicodeError , (), {'args' : (),}),
476
+ (UnicodeError , (), {}, { 'args' : (),}),
477
477
(UnicodeEncodeError , ('ascii' , 'a' , 0 , 1 ,
478
- 'ordinal not in range' ),
478
+ 'ordinal not in range' ), {},
479
479
{'args' : ('ascii' , 'a' , 0 , 1 ,
480
480
'ordinal not in range' ),
481
481
'encoding' : 'ascii' , 'object' : 'a' ,
482
482
'start' : 0 , 'reason' : 'ordinal not in range' }),
483
483
(UnicodeDecodeError , ('ascii' , bytearray (b'\xff ' ), 0 , 1 ,
484
- 'ordinal not in range' ),
484
+ 'ordinal not in range' ), {},
485
485
{'args' : ('ascii' , bytearray (b'\xff ' ), 0 , 1 ,
486
486
'ordinal not in range' ),
487
487
'encoding' : 'ascii' , 'object' : b'\xff ' ,
488
488
'start' : 0 , 'reason' : 'ordinal not in range' }),
489
489
(UnicodeDecodeError , ('ascii' , b'\xff ' , 0 , 1 ,
490
- 'ordinal not in range' ),
490
+ 'ordinal not in range' ), {},
491
491
{'args' : ('ascii' , b'\xff ' , 0 , 1 ,
492
492
'ordinal not in range' ),
493
493
'encoding' : 'ascii' , 'object' : b'\xff ' ,
494
494
'start' : 0 , 'reason' : 'ordinal not in range' }),
495
- (UnicodeTranslateError , ("\u3042 " , 0 , 1 , "ouch" ),
495
+ (UnicodeTranslateError , ("\u3042 " , 0 , 1 , "ouch" ), {},
496
496
{'args' : ('\u3042 ' , 0 , 1 , 'ouch' ),
497
497
'object' : '\u3042 ' , 'reason' : 'ouch' ,
498
498
'start' : 0 , 'end' : 1 }),
499
- (NaiveException , ('foo' ,),
499
+ (NaiveException , ('foo' ,), {},
500
500
{'args' : ('foo' ,), 'x' : 'foo' }),
501
- (SlottedNaiveException , ('foo' ,),
501
+ (SlottedNaiveException , ('foo' ,), {},
502
502
{'args' : ('foo' ,), 'x' : 'foo' }),
503
+ (AttributeError , ('foo' ,), dict (name = 'name' , obj = 'obj' ),
504
+ dict (args = ('foo' ,), name = 'name' , obj = 'obj' )),
503
505
]
504
506
try :
505
507
# More tests are in test_WindowsError
506
508
exceptionList .append (
507
- (WindowsError , (1 , 'strErrorStr' , 'filenameStr' ),
509
+ (WindowsError , (1 , 'strErrorStr' , 'filenameStr' ), {},
508
510
{'args' : (1 , 'strErrorStr' ),
509
511
'strerror' : 'strErrorStr' , 'winerror' : None ,
510
512
'errno' : 1 ,
@@ -513,11 +515,11 @@ def testAttributes(self):
513
515
except NameError :
514
516
pass
515
517
516
- for exc , args , expected in exceptionList :
518
+ for exc , args , kwargs , expected in exceptionList :
517
519
try :
518
- e = exc (* args )
520
+ e = exc (* args , ** kwargs )
519
521
except :
520
- print ("\n exc=%r , args=%r" % ( exc , args ) , file = sys .stderr )
522
+ print (f "\n exc={ exc !r } , args={ args !r } " , file = sys .stderr )
521
523
# raise
522
524
else :
523
525
# Verify module name
@@ -540,7 +542,12 @@ def testAttributes(self):
540
542
new = p .loads (s )
541
543
for checkArgName in expected :
542
544
got = repr (getattr (new , checkArgName ))
543
- want = repr (expected [checkArgName ])
545
+ if exc == AttributeError and checkArgName == 'obj' :
546
+ # See GH-103352, we're not pickling
547
+ # obj at this point. So verify it's None.
548
+ want = repr (None )
549
+ else :
550
+ want = repr (expected [checkArgName ])
544
551
self .assertEqual (got , want ,
545
552
'pickled "%r", attribute "%s' %
546
553
(e , checkArgName ))
0 commit comments