Author eric.araujo
Recipients Natim, alexis, eric.araujo, tarek
Date 2011-11-20.15:19:31
SpamBayes Score 5.40679e-13
Marked as misclassified No
Message-id <>
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.
Date User Action Args
2011-11-20 15:19:35eric.araujosetrecipients: + eric.araujo, tarek, alexis, Natim
2011-11-20 15:19:35eric.araujosetmessageid: <>
2011-11-20 15:19:34eric.araujolinkissue12703 messages
2011-11-20 15:19:34eric.araujocreate