[issue16801] Preserve original representation for integers / floats in docstrings

Serhiy Storchaka report at bugs.python.org
Sun Feb 24 10:19:56 CET 2013


Serhiy Storchaka added the comment:

It's cumbersome and burdensome because you need for every nonstandard default value:

1) define a class with __repr__();
2) instantiate a sentinel;
3) check for the sentinel in the function and replace it but an actual value.

    class _ExternalAttrDefault:
        def __repr__():
            return '(stat.S_IRUSR|stat.S_IRUSR)<<16'

    _external_attr_default = _ExternalAttrDefault()

    def open(self, name, mode='r', external_attr=_external_attr_default):
        if external_attr is _external_attr_default:
            external_attr = (stat.S_IRUSR|stat.S_IRUSR)<<16
        ...

Instead of just:

    def open(self, name, mode='r', external_attr=(stat.S_IRUSR|stat.S_IRUSR)<<16):
        """
        Foo.open(name, mode='r', external_attr=(stat.S_IRUSR|stat.S_IRUSR)<<16)
        """
        ...

----------

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


More information about the Python-bugs-list mailing list