This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author paul.j3
Recipients berker.peksag, bethard, mbussonn, paul.j3, serhiy.storchaka
Date 2015-06-03.20:52:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1433364727.43.0.393436218755.issue24360@psf.upfronthosting.co.za>
In-reply-to
Content
An alternative would be to wrap a non-identifier name in 'repr()':

    def repr1(self):
        def fmt_name(name):
            if name.isidentifier():
                return name
            else:
                return repr(name)
        type_name = type(self).__name__
        arg_strings = []
        for arg in self._get_args():
            arg_strings.append(repr(arg))
        for name, value in self._get_kwargs():
            arg_strings.append('%s=%r' % (fmt_name(name), value))
        return '%s(%s)' % (type_name, ', '.join(arg_strings))

This would produce lines like:

    Namespace(baz='one', 'foo bar'='test', 'x __y'='other')
    
    Namespace(a=1, b=2, 'double " quote'='"', "single ' quote "="'")

    Namespace(')'=3, a=1)

    Namespace(a=1, 'b=2), Namespace(c'=3)

With names that are deliberately messy, it is hard to say which is clearer.
History
Date User Action Args
2015-06-03 20:52:07paul.j3setrecipients: + paul.j3, bethard, berker.peksag, serhiy.storchaka, mbussonn
2015-06-03 20:52:07paul.j3setmessageid: <1433364727.43.0.393436218755.issue24360@psf.upfronthosting.co.za>
2015-06-03 20:52:07paul.j3linkissue24360 messages
2015-06-03 20:52:07paul.j3create