zhuyifei1999 added a comment.

I have no glue why the current implementation doesn't work.

Variable scopes.

diff --git a/pywikibot/comms/eventstreams.py b/pywikibot/comms/eventstreams.py
index a74baa1..e5ccd9c 100644
--- a/pywikibot/comms/eventstreams.py
+++ b/pywikibot/comms/eventstreams.py
@@ -219,15 +219,15 @@ 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
+                self.filter[ftype].append(lambda e: print(e, key, value) or 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
+                self.filter[ftype].append(lambda e: print(e, key, value) or 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
+                self.filter[ftype].append(lambda e: print(e, key, value) or key in e and
                                           e[key] in value)
 
     def streamfilter(self, data):

$ 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)
{'foo': True} bar baz
{'foo': True} bar baz
(False, False)
>>> c = {'bar': 'baz'}
>>> f(c), g(c)
{'bar': 'baz'} bar baz
{'bar': 'baz'} bar baz
(True, True)
>>> del stream

key and value belong to the closure of the outer function, not the loop iteration or the inner lambda.


TASK DETAIL
https://phabricator.wikimedia.org/T188832

EMAIL PREFERENCES
https://phabricator.wikimedia.org/settings/panel/emailpreferences/

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
_______________________________________________
pywikibot-bugs mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-bugs

Reply via email to