New submission from Adam Bielański:

Issue: cgitb text formatter outputs all members of exception object, using 
standard dir() to get their names.

My patch changes its behaviour to skip fields which are callable, since 
printing them only clutters the output but is rarely helpful.


HTML formatter skips members starting with underscore (_), which is slightly 
different behaviour and I can alter my patch to make both formatters behave in 
the same way, should the need be. Both can skip members starting with 
underscore, callables, or callables and values starting with underscore - any 
option will be better than printing them all.


Current change alters output for exception value Exception("123412312") from:

<type 'exceptions.Exception'>: 123412312
    __class__ = <type 'exceptions.Exception'>
    __delattr__ = <method-wrapper '__delattr__' of exceptions.Exception object>
    __dict__ = {}
    __doc__ = 'Common base class for all non-exit exceptions.'
    __format__ = <built-in method __format__ of exceptions.Exception object>
    __getattribute__ = <method-wrapper '__getattribute__' of 
exceptions.Exception object>
    __getitem__ = <method-wrapper '__getitem__' of exceptions.Exception object>
    __getslice__ = <method-wrapper '__getslice__' of exceptions.Exception 
object>
    __hash__ = <method-wrapper '__hash__' of exceptions.Exception object>
    __init__ = <method-wrapper '__init__' of exceptions.Exception object>
    __new__ = <built-in method __new__ of type object>
    __reduce__ = <built-in method __reduce__ of exceptions.Exception object>
    __reduce_ex__ = <built-in method __reduce_ex__ of exceptions.Exception 
object>
    __repr__ = <method-wrapper '__repr__' of exceptions.Exception object>
    __setattr__ = <method-wrapper '__setattr__' of exceptions.Exception object>
    __setstate__ = <built-in method __setstate__ of exceptions.Exception object>
    __sizeof__ = <built-in method __sizeof__ of exceptions.Exception object>
    __str__ = <method-wrapper '__str__' of exceptions.Exception object>
    __subclasshook__ = <built-in method __subclasshook__ of type object>
    __unicode__ = <built-in method __unicode__ of exceptions.Exception object>
    args = ('123412312',)
    message = '123412312'


to:

<type 'exceptions.Exception'>: 123412312
    __dict__ = {}
    __doc__ = 'Common base class for all non-exit exceptions.'
    args = ('123412312',)
    message = '123412312'

----------
components: Library (Lib)
files: cgitb.diff
keywords: patch
messages: 266749
nosy: Adam.Bielański
priority: normal
severity: normal
status: open
title: Skip callables when displaying exception fields in cgitb
type: enhancement
versions: Python 3.5, Python 3.6
Added file: http://bugs.python.org/file43065/cgitb.diff

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue27165>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to