Skip to content

Commit 95e5473

Browse files
committed
fix: replace bare except with except Exception in skills scripts
Follow-up to the analysis.py fix - apply the same PEP 8 best practice to the remaining scripts: - skills/publish-to-pages/scripts/convert-pdf.py (1 instance) - skills/publish-to-pages/scripts/convert-pptx.py (9 instances) - skills/datanalysis-credit-risk/references/func.py (2 instances) Bare except clauses catch SystemExit and KeyboardInterrupt which prevents clean process termination. Signed-off-by: Srikanth Patchava <spatchava@meta.com>
1 parent 60463ec commit 95e5473

4 files changed

Lines changed: 12 additions & 12 deletions

File tree

skills/datanalysis-credit-risk/references/func.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def get_dataset(data_pth: str, date_colName: str, y_colName: str,
4141
try:
4242
data = reader(data_pth)
4343
break
44-
except:
44+
except Exception:
4545
continue
4646

4747
# Replace abnormal values with NaN
@@ -196,7 +196,7 @@ def export_report_xlsx(filepath: str, data_name: str, data: pd.DataFrame,
196196
from openpyxl import load_workbook
197197
wb = load_workbook(filepath)
198198
ws = wb.create_sheet(sheet_name)
199-
except:
199+
except Exception:
200200
wb = Workbook()
201201
ws = wb.active
202202
ws.title = sheet_name
@@ -225,4 +225,4 @@ def export_report_xlsx(filepath: str, data_name: str, data: pd.DataFrame,
225225
cell.alignment = Alignment(horizontal='center')
226226

227227
wb.save(filepath)
228-
print(f"[{sheet_name}] Saved to {filepath}")
228+
print(f"[{sheet_name}] Saved to {filepath}")

skills/publish-to-pages/scripts/convert-pdf.py

100755100644
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def get_page_count(pdf_path):
2424
for line in result.stdout.splitlines():
2525
if line.startswith("Pages:"):
2626
return int(line.split(":")[1].strip())
27-
except:
27+
except Exception:
2828
pass
2929
return None
3030

skills/publish-to-pages/scripts/convert-pptx.py

100755100644
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def rgb_to_hex(rgb_color):
2626
return None
2727
try:
2828
return f"#{rgb_color}"
29-
except:
29+
except Exception:
3030
return None
3131

3232

@@ -45,7 +45,7 @@ def get_text_style(run):
4545
styles.append(f"color:{rgb_to_hex(run.font.color.rgb)}")
4646
if run.font.name:
4747
styles.append(f"font-family:'{run.font.name}',sans-serif")
48-
except:
48+
except Exception:
4949
pass
5050
return ";".join(styles)
5151

@@ -60,7 +60,7 @@ def get_alignment(paragraph):
6060
return "right"
6161
elif align == PP_ALIGN.JUSTIFY:
6262
return "justify"
63-
except:
63+
except Exception:
6464
pass
6565
return "left"
6666

@@ -72,7 +72,7 @@ def get_shape_position(shape, slide_width, slide_height):
7272
width = (shape.width / slide_width) * 100 if shape.width else 50
7373
height = (shape.height / slide_height) * 100 if shape.height else 30
7474
return left, top, width, height
75-
except:
75+
except Exception:
7676
return 5, 5, 90, 40
7777

7878

@@ -85,7 +85,7 @@ def get_slide_background(slide, prs):
8585
clr = sf.find(qn('a:srgbClr'))
8686
if clr is not None and clr.get('val'):
8787
return f"background-color:#{clr.get('val')}"
88-
except:
88+
except Exception:
8989
pass
9090
return "background-color:#ffffff"
9191

@@ -108,7 +108,7 @@ def get_shape_fill(shape):
108108
clr = sf.find(qn('a:srgbClr'))
109109
if clr is not None and clr.get('val'):
110110
return f"#{clr.get('val')}"
111-
except:
111+
except Exception:
112112
pass
113113
return None
114114

@@ -137,7 +137,7 @@ def extract_image_data(shape):
137137
try:
138138
image = shape.image
139139
return image.blob, image.content_type
140-
except:
140+
except Exception:
141141
return None, None
142142

143143

@@ -150,7 +150,7 @@ def count_images(prs):
150150
try:
151151
_ = shape.image
152152
count += 1
153-
except:
153+
except Exception:
154154
pass
155155
return count
156156

skills/publish-to-pages/scripts/publish.sh

100755100644
File mode changed.

0 commit comments

Comments
 (0)