[issue12703] Improve error reporting for packaging.util.resolve_name

Éric Araujo report at bugs.python.org
Sun Nov 20 16:19:35 CET 2011


Éric Araujo <merwok at netwok.org> added the comment:

I’ve found a way to make sure error messages always bubble up *and* clean up the ugly code in resolve_name, but it’s a rather drastic one.  The idea is to restrict the function to work only with names defined at the module level, not arbitrarily nested names.  That way, the code is much easier to write: split on '.', pop the last element and keep it for later, __import__ the rest of the name and look it up in sys.modules.  One consequence is that you can’t use package.module.SomeClass.NestedClass for a command, nor module.SomeClass.staticmethod as setup hook; to be pragmatic, I’m not sure that was really useful, and in any case you just have to do a module-level alias (“x = SomeClass.staticmethod”) to make it work.

To reflect the fact that the function has restrictions, I renamed it from the generic “resolve_name” to the vague “find_object”; vague is better because it makes less promises and should cause developers using to look at the docs or docstring.

In short, it’s a clear improvement code-wise that should not impact most of the users, and I like it a lot.

----------
stage: test needed -> patch review
Added file: http://bugs.python.org/file23735/change-resolve-name.diff

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


More information about the Python-bugs-list mailing list