@@ -397,10 +397,12 @@ class ExceptionInfo(Generic[_E]):
397
397
_traceback = attr .ib (type = Optional [Traceback ], default = None )
398
398
399
399
@classmethod
400
- def from_current (
401
- cls , exprinfo : Optional [str ] = None
402
- ) -> "ExceptionInfo[BaseException]" :
403
- """returns an ExceptionInfo matching the current traceback
400
+ def from_exc_info (
401
+ cls ,
402
+ exc_info : Tuple ["Type[_E]" , "_E" , TracebackType ],
403
+ exprinfo : Optional [str ] = None ,
404
+ ) -> "ExceptionInfo[_E]" :
405
+ """returns an ExceptionInfo for an existing exc_info tuple.
404
406
405
407
.. warning::
406
408
@@ -411,20 +413,37 @@ def from_current(
411
413
strip ``AssertionError`` from the output, defaults
412
414
to the exception message/``__str__()``
413
415
"""
414
- tup_ = sys .exc_info ()
415
- assert tup_ [0 ] is not None , "no current exception"
416
- assert tup_ [1 ] is not None , "no current exception"
417
- assert tup_ [2 ] is not None , "no current exception"
418
- tup = (tup_ [0 ], tup_ [1 ], tup_ [2 ])
419
416
_striptext = ""
420
- if exprinfo is None and isinstance (tup [1 ], AssertionError ):
421
- exprinfo = getattr (tup [1 ], "msg" , None )
417
+ if exprinfo is None and isinstance (exc_info [1 ], AssertionError ):
418
+ exprinfo = getattr (exc_info [1 ], "msg" , None )
422
419
if exprinfo is None :
423
- exprinfo = saferepr (tup [1 ])
420
+ exprinfo = saferepr (exc_info [1 ])
424
421
if exprinfo and exprinfo .startswith (cls ._assert_start_repr ):
425
422
_striptext = "AssertionError: "
426
423
427
- return cls (tup , _striptext )
424
+ return cls (exc_info , _striptext )
425
+
426
+ @classmethod
427
+ def from_current (
428
+ cls , exprinfo : Optional [str ] = None
429
+ ) -> "ExceptionInfo[BaseException]" :
430
+ """returns an ExceptionInfo matching the current traceback
431
+
432
+ .. warning::
433
+
434
+ Experimental API
435
+
436
+
437
+ :param exprinfo: a text string helping to determine if we should
438
+ strip ``AssertionError`` from the output, defaults
439
+ to the exception message/``__str__()``
440
+ """
441
+ tup = sys .exc_info ()
442
+ assert tup [0 ] is not None , "no current exception"
443
+ assert tup [1 ] is not None , "no current exception"
444
+ assert tup [2 ] is not None , "no current exception"
445
+ exc_info = (tup [0 ], tup [1 ], tup [2 ])
446
+ return cls .from_exc_info (exc_info )
428
447
429
448
@classmethod
430
449
def for_later (cls ) -> "ExceptionInfo[_E]" :
0 commit comments