aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar S. Co1 <[email protected]>2020-01-11 17:38:46 -0500
committerGravatar S. Co1 <[email protected]>2020-01-11 17:38:46 -0500
commiteaaebe963c0b9f79ce18142e343f57ef85fdd88c (patch)
treedf751cafae80768dc7afa6c1a7fdc92f50d72bb2
parentUpdate Code Jam Participant ID (diff)
Add handling for empty PEP metadata values
Some PEPs have a metadata field that is present but has an empty value (e.g. PEP 249), causing an exception to be raised when attempting to add it as an embed field value, which cannot be empty. This refactors the information parsing to prevent the field from being added if there is no value to provide, as well as cut down on copy+paste when populating fields in the embed.
-rw-r--r--bot/cogs/utils.py14
1 files changed, 6 insertions, 8 deletions
diff --git a/bot/cogs/utils.py b/bot/cogs/utils.py
index 47a59db66..da278011a 100644
--- a/bot/cogs/utils.py
+++ b/bot/cogs/utils.py
@@ -62,14 +62,12 @@ class Utils(Cog):
pep_embed.set_thumbnail(url="https://www.python.org/static/opengraph-icon-200x200.png")
# Add the interesting information
- if "Status" in pep_header:
- pep_embed.add_field(name="Status", value=pep_header["Status"])
- if "Python-Version" in pep_header:
- pep_embed.add_field(name="Python-Version", value=pep_header["Python-Version"])
- if "Created" in pep_header:
- pep_embed.add_field(name="Created", value=pep_header["Created"])
- if "Type" in pep_header:
- pep_embed.add_field(name="Type", value=pep_header["Type"])
+ fields_to_check = ("Status", "Python-Version", "Created", "Type")
+ for field in fields_to_check:
+ # Check for a PEP metadata field that is present but has an empty value
+ # embed field values can't contain an empty string
+ if pep_header.get(field, ""):
+ pep_embed.add_field(name=field, value=pep_header[field])
elif response.status != 404:
# any response except 200 and 404 is expected