[issue8887] “pydoc str” works but not “pydoc str.translate”

Alexander Belopolsky report at bugs.python.org
Fri May 27 18:12:11 CEST 2011


Alexander Belopolsky <belopolsky at users.sourceforge.net> added the comment:

The patch looks good.  A nit-pick:

+        if len(parts) > 0:

Since *parts* is a list, the above can be replaced with simply "if parts:".

Also, it seems to me that the new code may produce an AttributeError when given invalid name, but locate() function is supposed to return None instead.

I wouder if it would be possible to reuse the try/except logic ing the "if module" clause and simply do something like

    if module:
        object = module
    else:
        object = builtins
    for part in parts[n:]:
        try:
            object = getattr(object, part)
        except AttributeError:
            return None
    return object

----------

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


More information about the Python-bugs-list mailing list