Dynamic imports

25 views
Skip to first unread message

Rodrigo Moraes

unread,
Mar 13, 2010, 8:50:04 AM3/13/10
to Python Inject
Heya. Interesting project you have there (but I'm still not totally
familiar with it).

I had a quick idea. How about making the injected callable dynamically
imported if it is set as a string. Something along the lines of...

class Controller(object):
user = inject.attr('user', type='my.module.get_user',
scope=inject.reqscope)

This would led to less required imports -- inject would resolve
'my.module.get_user' as needed. Similar mechanism would need to be
implemented for bindto. Horrible idea? :)

Keep it up. Very well designed little library.

-- rodrigo

Ivan Korobkov

unread,
Mar 15, 2010, 3:48:41 AM3/15/10
to python...@googlegroups.com
Hi.

The idea of auto imports is quite good. However, it has some disadvantages:
1. It makes an application very difficult to test and debug.
2. Specifying an import as a string is not supported by IDEs, 
i.e. no autocomplete, no refactoring, etc.
3. It contradicts to the unix nature: one feature -- one tool,
in other words, it won't be inject's internal feature.

In my opinion, it can be useful only when you need to prevent cyclic imports.
Maybe, I will add this functionality in the future versions.


-- 
Ivan Korobkov
Reply all
Reply to author
Forward
0 new messages