feedparser
feedparser copied to clipboard
spurious deprecation warnings
recently (since after 5.1.3) the feed2exec test suite started failing because this warning was mangling the output of the script:
/home/anarcat/src/feed2exec/.tox/py36/lib/python3.6/site-packages/feedparser.py:345: DeprecationWarning: To avoid breaking existing software while fixing issue 310, a temporary mapping has been created from `updated_parsed` to `published_parsed` if `updated_parsed` doesn't exist. This fallback will be removed in a future version of feedparser.
It's unclear to me how to disable this warning. Any access of the property will trigger the warning. I believe the should be a way to behave properly for the library consumers and disable the warning, for example by having a default value for the get
parameter. I have tried that, without any luck:
--- c/feed2exec/email.py
+++ i/feed2exec/email.py
@@ -97,7 +97,7 @@ def make_message(feed, item, to_addr=None, cls=email.message.Message):
#
# also, default on the feed updated date
orig = timestamp = datetime.datetime.utcnow().timestamp()
- timestamp = item.get('updated_parsed') or orig
+ timestamp = item.get('updated_parsed', item.get('published_parsed', orig))
if isinstance(timestamp, (datetime.datetime,
datetime.date,
datetime.time)):
I have reverted to silencing the warnings altogether, which seems suboptimal. It would be better if there was a way to comply with the deprecation warning correctly without having to disable warnings.
Thanks!
@anarcat your code is still accessing updated_parsed even when published_parsed exists. I think you want this instead:
timestamp = item.get('published_parsed') or orig
or, if you intend to keep feed2exec compatible with older feedparser versions that do not provide published_parsed, you could do
timestamp = item.get('published_parsed') or item.get('updated_parsed') or orig
but that would prioritize published_parsed
over updated_parsed
which is not what i want. it would also still yield warnings if published_parsed
is missing or empty.
So in general should I be using updated_parsed
instead of trying to get published_parsed
?
that is the question. the deprecation warning here should make it clearer what the proper way out is. right now it's ambiguous.
I've stumbled upon the same error today, @kurtmckee which is the official position on using updated_parsed
or published_parsed
?