From: W. Trevor King Date: Wed, 25 Feb 2015 18:07:34 +0000 (-0800) Subject: feed: Don't pop from extra_headers while iterating over it X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=60870d9ff7f23441919df79d710ad49ecbcedf73;p=rss2email.git feed: Don't pop from extra_headers while iterating over it Avoid: Traceback (most recent call last): ... for k,v in extra_headers.items(): File "/.../Python-3.5.0a1/Lib/_collections_abc.py", line 503, in __iter__ for key in self._mapping: File "/.../Python-3.5.0a1/Lib/collections/__init__.py", line 112, in __iter__ yield curr.key AttributeError: 'NoneType' object has no attribute 'key' from continuing to iterate on items() after popping a key. This worked in Python 3.4 but no longer works in Python 3.5. In any case, mutating an object while iterating over it is always a bit questionable, so rephrase to find the keys in one pass, and then remove them after the iteration completes. Reported-by: Raniere Silva Signed-off-by: W. Trevor King --- diff --git a/rss2email/feed.py b/rss2email/feed.py index ec5c4f6..f2750ef 100644 --- a/rss2email/feed.py +++ b/rss2email/feed.py @@ -470,9 +470,10 @@ class Feed (object): ('X-RSS-URL', self._get_entry_link(entry)), ('X-RSS-TAGS', self._get_entry_tags(entry)), )) - for k,v in extra_headers.items(): # remove empty tags, etc. - if v is None: - extra_headers.pop(k) + # remove empty tags, etc. + keys = {k for k, v in extra_headers.items() if v is None} + for key in keys: + extra_headers.pop(key) if self.bonus_header: for header in self.bonus_header.splitlines(): if ':' in header: