Skip to content

Commit

Permalink
Fix some 'too broad exception' and 'shadows built-in name' warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
matyasselmeci committed May 20, 2024
1 parent 84d363c commit c10a3e3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/webapp/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def get_yaml(self, resources, service_names_by_resource) -> str:
yaml = ""
for index, resource in enumerate(resources):
yaml += models.get_downtime_yaml(
id=dtid+index,
id_=dtid + index,
start_datetime=self.get_start_datetime(),
end_datetime=self.get_end_datetime(),
created_datetime=created_datetime,
Expand Down Expand Up @@ -293,7 +293,7 @@ def get_yaml(self) -> str:
dtid = models._dtid(created_datetime)

return models.get_downtime_yaml(
id=dtid,
id_=dtid,
start_datetime=self.get_start_datetime(),
end_datetime=self.get_end_datetime(),
created_datetime=created_datetime,
Expand Down
44 changes: 22 additions & 22 deletions src/webapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ def get_contact_db_data(self) -> Optional[ContactsData]:
if ok:
try:
self.contacts_data.update(contacts_reader.get_contacts_data(self.contacts_file))
except Exception:
except Exception as err:
if self.strict:
raise
log.exception("Failed to update contacts data")
log.exception("Failed to update contacts data (%s)", err)
self.contacts_data.try_again()
else:
self.contacts_data.try_again()
Expand All @@ -213,10 +213,10 @@ def get_comanage_data(self) -> Optional[ContactsData]:
idmap = self.get_cilogon_ldap_id_map()
data = ldap_data.cilogon_id_map_to_yaml_data(idmap)
self.comanage_data.update(ContactsData(data))
except Exception:
except Exception as err:
if self.strict:
raise
log.exception("Failed to update comanage data")
log.exception("Failed to update comanage data (%s)", err)
self.comanage_data.try_again()

return self.comanage_data.data
Expand All @@ -238,10 +238,10 @@ def get_contacts_data(self) -> Optional[ContactsData]:
yd2 = self.get_contact_db_data().yaml_data
yd_merged = ldap_data.merge_yaml_data(yd1, yd2)
self.merged_contacts_data.update(ContactsData(yd_merged))
except Exception:
except Exception as err:
if self.strict:
raise
log.exception("Failed to update merged contacts data")
log.exception("Failed to update merged contacts data (%s)", err)
self.merged_contacts_data.try_again()

return self.merged_contacts_data.data
Expand All @@ -262,10 +262,10 @@ def get_ligo_dn_list(self) -> Optional[List[str]]:
ligo_ldap_pass = readfile(self.ligo_ldap_passfile, log)
new_dn_list = ldap_data.get_ligo_ldap_dn_list(self.ligo_ldap_url, self.ligo_ldap_user, ligo_ldap_pass)
self.ligo_dn_list.update(new_dn_list)
except Exception:
except Exception as err:
if self.strict:
raise
log.exception("Failed to update LIGO data")
log.exception("Failed to update LIGO data (%s)", err)
self.ligo_dn_list.try_again()

return self.ligo_dn_list.data
Expand All @@ -279,10 +279,10 @@ def get_dns(self) -> Optional[Set]:
contacts_data = self.get_contacts_data()
try:
self.dn_set.update(set(contacts_data.get_dns()))
except Exception:
except Exception as err:
if self.strict:
raise
log.exception("Failed to update DNs")
log.exception("Failed to update DNs (%s)", err)
self.contacts_data.try_again()
return self.dn_set.data

Expand All @@ -305,10 +305,10 @@ def update_topology(self):
if ok:
try:
self.topology.update(rg_reader.get_topology(self.topology_dir, self.get_contacts_data(), strict=self.strict))
except Exception:
except Exception as err:
if self.strict:
raise
log.exception("Failed to update topology")
log.exception("Failed to update topology (%s)", err)
self.topology.try_again()
else:
self.topology.try_again()
Expand All @@ -324,10 +324,10 @@ def get_vos_data(self) -> Optional[VOsData]:
if ok:
try:
self.vos_data.update(vo_reader.get_vos_data(self.vos_dir, self.get_contacts_data(), strict=self.strict))
except Exception:
except Exception as err:
if self.strict:
raise
log.exception("Failed to update VOs")
log.exception("Failed to update VOs (%s)", err)
self.vos_data.try_again()
else:
self.vos_data.try_again()
Expand All @@ -345,10 +345,10 @@ def get_projects(self) -> Optional[Dict]:
if ok:
try:
self.projects.update(project_reader.get_projects(self.projects_dir, strict=self.strict))
except Exception:
except Exception as err:
if self.strict:
raise
log.exception("Failed to update projects")
log.exception("Failed to update projects (%s)", err)
self.projects.try_again()
else:
self.projects.try_again()
Expand All @@ -368,10 +368,10 @@ def get_mappings(self, strict=None) -> Optional[mappings.Mappings]:
if ok:
try:
self.mappings.update(mappings.get_mappings(indir=self.mappings_dir, strict=strict))
except Exception:
except Exception as err:
if self.strict:
raise
log.exception("Failed to update mappings")
log.exception("Failed to update mappings (%s)", err)
self.mappings.try_again()
else:
self.mappings.try_again()
Expand All @@ -387,7 +387,7 @@ def _dtid(created_datetime: datetime.datetime):
return int((timestamp - dtid_offset) * multiplier)


def get_downtime_yaml(id: int,
def get_downtime_yaml(id_: int,
start_datetime: datetime.datetime,
end_datetime: datetime.datetime,
created_datetime: datetime.datetime,
Expand All @@ -403,8 +403,8 @@ def get_downtime_yaml(id: int,
"""

def render(key, value):
return yaml.safe_dump({key: value}, default_flow_style=False).strip()
def render(key_, value_):
return yaml.safe_dump({key_: value_}, default_flow_style=False).strip()

def indent(in_str, amount):
spaces = ' ' * amount
Expand All @@ -416,7 +416,7 @@ def indent(in_str, amount):

result = "- " + render("Class", class_)
for key, value in [
("ID", id),
("ID", id_),
("Description", description),
("Severity", severity),
("StartTime", start_time_str),
Expand Down

0 comments on commit c10a3e3

Please sign in to comment.