[issue26389] Expand traceback module API to accept just an exception as an argument

Matthias Bussonnier report at bugs.python.org
Fri Mar 3 00:30:00 EST 2017


Matthias Bussonnier added the comment:

> (Optional) Change 'value' to 'exc' in the API to reflect the 3.x restriction Keep the synonym until after 2.7. 

Do you mean after 2.7 EOL, or after 3.7 ?


> etype: In 3.5+ document that it is an ignored dummy argument and that one can just pass 0, '', or None.
> (Optional) Deprecate the parameter and make it optional.  This can be handled* in the code and would be like range having option 'start'.  This is messy but would be temporary.  

That seem hard to do if we want to allow func(exception), should we attempt to emit a deprecation warning only when etype is used in the Legacy Form ?

> Remove after 2.7.

Same question as above, unsure what you mean. 


> (Optional) Change 'value' to 'exc' in the API to reflect the 3.x restriction. Document 'value' as a deprecated synonym for keyword usage.

That seem like overly complicated as now the actual exception object can be either in etype, value, or exc. 


Let my try to give example to see if I understood correctly

2.7 compat

    print_exception(etype, value, tb)
    print_exception(etype=etype, value=value, tb=tb) 

3.5 compat
    print_exception(None, value, tb)
    print_exception(etype=None, value=value, tb=tb)
                                      
3.7
    print_exception(value)              == print_exception(type(value), value, value.__traceback__)
    print_exception(value, tb=True)     == print_exception(type(value), value, value.__traceback__)

    print_exception(value, tb=None)     == print_exception(type(value), value, None)
    print_exception(value, tb=False)    == print_exception(type(value), value, None)


    print_exception(value, tb=faketb)   == print_exception(type(value), value, faketb)
                                  
    # tb can be positional

    print_exception(value, tb) == print_exception(value, tb=tb)

Signature would thus be:

    if first param isinstance BaseException: # 3.7+, prefered form
        print_exception(exc, [tb ,] *, [limit, file, chain])
    else:
        print_exception(etype, value, tb, [limit, file, chain])
        # etype being ignored

Should exc be positional only ?

    print_exception(exc, /, [tb ,] *, [limit, file, chain])

Should `limit`, `file`, `chain` be allowed to be positional ?

    print_exception(exc, [tb , limit, file, chain])

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26389>
_______________________________________


More information about the Python-bugs-list mailing list