| zhuyifei1999 added a comment. |
One way to solve this without using more lambdas:
diff --git a/pywikibot/comms/eventstreams.py b/pywikibot/comms/eventstreams.py index a74baa1..b48ecc8 100644 --- a/pywikibot/comms/eventstreams.py +++ b/pywikibot/comms/eventstreams.py @@ -219,16 +219,16 @@ class EventStreams(object): for key, value in kwargs.items(): # append function for singletons if isinstance(value, (bool, type(None))): - self.filter[ftype].append(lambda e: key in e and - e[key] is value) + self.filter[ftype].append(lambda e, _key=key, _value=value: + _key in e and e[_key] is _value) # append function for a single value elif isinstance(value, (StringTypes, int)): - self.filter[ftype].append(lambda e: key in e and - e[key] == value) + self.filter[ftype].append(lambda e, _key=key, _value=value: + _key in e and e[_key] == _value) # append function for an iterable as value else: - self.filter[ftype].append(lambda e: key in e and - e[key] in value) + self.filter[ftype].append(lambda e, _key=key, _value=value: + _key in e and e[_key] in _value) def streamfilter(self, data): """Filter function for eventstreams.
$ PYWIKIBOT2_NO_USER_CONFIG=1 python3 pwb.py shell Skipping loading of user-config.py. family and mylang are not set. Defaulting to family='test' and mylang='test'. Welcome to the Pywikibot interactive shell! >>> from pywikibot.comms.eventstreams import EventStreams >>> stream = EventStreams(stream='recentchange') >>> stream.register_filter(foo=True, bar='baz') >>> f, g = stream.filter['all'] >>> c = {'foo': True} >>> f(c), g(c) (True, False) >>> c = {'bar': 'baz'} >>> f(c), g(c) (False, True) >>> del stream
TASK DETAIL
EMAIL PREFERENCES
To: Xqt, zhuyifei1999
Cc: zhuyifei1999, valhallasw, Dalba, Ottomata, Aklapper, Zoranzoki21, Xqt, pywikibot-bugs-list, Magul, Tbscho, rafidaslam, MayS, Mdupont, JJMC89, Avicennasis, jayvdb, Masti, Alchimista, Rxy
Cc: zhuyifei1999, valhallasw, Dalba, Ottomata, Aklapper, Zoranzoki21, Xqt, pywikibot-bugs-list, Magul, Tbscho, rafidaslam, MayS, Mdupont, JJMC89, Avicennasis, jayvdb, Masti, Alchimista, Rxy
_______________________________________________ pywikibot-bugs mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/pywikibot-bugs
