traceback.format_exc() returns 'None\n'?!

Peter Otten __peter__ at web.de
Thu Aug 31 17:48:48 EDT 2017


Sean DiZazzo wrote:

> Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 12:39:47)
> [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import traceback
>>>> tb = traceback.format_exc()
>>>> type(tb)
> <type 'str'>
>>>> tb
> 'None\n'
>>>> 
> 
> 
> Shouldn't it just return None itself?  

No. The function expects that there is a current exception. That's not the 
case here, and thus it should complain in the usual way -- by raising an 
exception. However, this function has been around for a while which rules 
out such a disruptive change.

> Why a string with a newline?
> 
> Interested if there is an actual reason for this behavior 

An implementation accident, if I were to guess.

> or if it should
> be reported as a bug.

Certainly not.




More information about the Python-list mailing list