Skip to content

Commit ac32b81

Browse files
committed
style: fix ruff SIM102 and PERF203 warnings
- Combine nested if statements in fill_links_from_history (SIM102) - Extract validate_conference helper to avoid try-except in loop (PERF203)
1 parent bdd0b19 commit ac32b81

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

utils/import_python_official.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,13 @@ def fill_links_from_history(df_ics: pd.DataFrame, df_yml: pd.DataFrame) -> pd.Da
6666
link = row.get("link", "")
6767
year = row.get("year", 0)
6868

69-
if conf_name and link:
70-
# Keep the most recent link for each conference
71-
if conf_name not in historical_links or year > historical_links[conf_name][1]:
72-
historical_links[conf_name] = (link, year)
69+
# Keep the most recent link for each conference
70+
if (
71+
conf_name
72+
and link
73+
and (conf_name not in historical_links or year > historical_links[conf_name][1])
74+
):
75+
historical_links[conf_name] = (link, year)
7376

7477
filled_count = 0
7578
for idx, row in df_ics.iterrows():

utils/sort_yaml.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -301,17 +301,19 @@ def sort_data(base="", prefix="", skip_links=False):
301301
for i, q in enumerate(data.copy()):
302302
data[i] = order_keywords(q)
303303

304-
logger.info("✅ Validating conference data with Pydantic schema")
305-
new_data = []
306-
validation_errors = 0
307-
308-
for q in data:
304+
def validate_conference(q: dict) -> Conference | None:
305+
"""Validate a single conference entry, returning None if invalid."""
309306
try:
310-
new_data.append(Conference(**q))
307+
return Conference(**q)
311308
except pydantic.ValidationError as e:
312-
validation_errors += 1
313309
logger.error(f"❌ Validation error in conference: {e}")
314310
logger.debug(f"Invalid data: \n{yaml.dump(q, default_flow_style=False)}")
311+
return None
312+
313+
logger.info("✅ Validating conference data with Pydantic schema")
314+
validated = [validate_conference(q) for q in data]
315+
new_data = [c for c in validated if c is not None]
316+
validation_errors = len(validated) - len(new_data)
315317

316318
if validation_errors > 0:
317319
logger.warning(f"⚠️ {validation_errors} conferences failed validation and were skipped")

0 commit comments

Comments
 (0)