-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the ability to filter which implementors of an Interface will be returned #11
Comments
Crazy suggestionsMaybe you can use something like java loggers, using canonical name Something like: MyInterface.implementors('br.com.something') #all implementators from br.com.something import *
MyInterface.implementors('br.com') #all implementators from br.com import *
MyInterface.implementors('br') #all implementators from br import * Another cool stuff are more like jquery do where you can pass one string (use canonical name), one function (like you suggest) Or you can use css filters: MyInterface.implementors('bla') #get implementations with class name == "bla"
MyInterface.implementors('ble bla') #get implementations with class name == "bla" sub class of ''ble'
MyInterface.implementors('.bla') #get implementations with attr class == "somenthig bla otherthing"
MyInterface.implementors('.ble.bla') #get implementations with attr class == "somenthig bla ble otherthing"
MyInterface.implementors('#someid') #get implementations with id attr = someid
MyInterface.implementors('[bla]') #get implementations with attr bla
MyInterface.implementors('[bla="ble"]') #get implementations with attr bla == "ble"
MyInterface.implementors(callback) #use function Using this you have more features then are usually needed :) You don't need use all css selectors. |
Other idea, Use ref #12 idea for filter ...
implements = [(MyInterface, X)]
..
implements = [(MyInterface, Y)]
...
MyInterface.implementors(X)
#to be more perfect http://guide.couchdb.org/draft/views.html#many I liked idea for iterator with 'filter' but more if you create one .not function. |
The css selector style is indeed powerful but would increase cinsiderable the internal complexity of plugnplay. I'd rather keep the codebase simple and go with the filter function approach. |
I liked callback approach. But are better if we can pass parameters to callback def callback(obj, *args, **kw):
return len(obj) > kw.get('min_len', 5)
def callback_x(obj, x):
return len(obj) > x
MyInterface.implementors(callback)
MyInterface.implementors(callback, min_len=7)
MyInterface.implementors(callback_x, 8) |
This is indeed interesting!!! Will think about it! Thanks! |
The Manager is already capable of receiving a filter callback function to filter the returned implementors list. ref #11
It's done. I will leave this code on this branch for a while and merge it back to develop branch soon. |
What you do in bad cases, when filter aren't callable, user pass more params that defined for function ...? |
In this case I let the exception to be raised by the python interpreter. Don' t know if there is anything that plugnplay could do. Raise an exception or let a generic exception be raised by the interpreter seems the same. And I think that failing silently would be worse, because this would cause too much confusion. I think passing wrong arguments or a non callable object is a development problem and should be catched at develop time. Any way, just guessing. |
Currently plugnplay always returns all implementors of an Interface when you call
MyInterface.implementors()
. The idea of this issue is to be able to filter which implementors will be returned by this call.The first idea would be to pass a callback to the
implementors
classmethod, something on the same line of Python's built-infilter
function.A simple example:
Assuming that all implementors of
MyInterface
responds to the__len__
method, only implementors bigger than 5 would be returned by this call.Another idea:
implementors()
could return a custom iterable object that has afiler()
method. This way you could continue to have this code:but at the same time you could do this:
to iterate on a filtered list of implementors.
The text was updated successfully, but these errors were encountered: