fix: replace bare except with specific exception types (Fixes #1173) - #1174
fix: replace bare except with specific exception types (Fixes #1173)#1174rtmalikian wants to merge 1 commit into
Conversation
…iuc#1173) - ranking.py: except: -> except ImportError: (pytrec_eval import) - quicksearch.py: except: -> except ImportError: (cython import) - base_dataset.py: except: -> except Exception: (queue.get timeout) - favmac/core.py: except: -> except Exception: (greedy maximize fallback) Bare except: clauses also catch KeyboardInterrupt and SystemExit, preventing graceful shutdown and masking bugs during debugging. Signed-off-by: rtmalikian <rtmalikian@gmail.com>
|
Thanks for taking this on. Bare 1.
|
Fixes #1173
Problem
Five bare
except:clauses across 4 files silently catchKeyboardInterrupt,SystemExit, andGeneratorExitin addition to intended exceptions. This prevents graceful shutdown, masks bugs, and makes debugging harder.Solution
Replace each bare
except:with the specific exception type it's intended to handle:pyhealth/metrics/ranking.py:except:→except ImportError:(pytrec_eval import)pyhealth/calib/predictionset/scrib/quicksearch.py:except:→except ImportError:(cython import)pyhealth/datasets/base_dataset.py: twoexcept:→except Exception:(queue.get timeout — raisesEmptyfromqueuemodule but safer to catchExceptionfor robustness)pyhealth/calib/predictionset/favmac/core.py:except:→except Exception:(greedy maximize fallback — intentionally catches any algorithm failure)The ImportError cases are semantically identical (the except block re-raises or prints a message). The queue and greedy cases switch to
except Exception:which still catches all runtime errors but allowsKeyboardInterruptandSystemExitto propagate.Verification
ast.parse()syntax checkgit diff --statshows exactly 5 insertions / 5 deletionsChangelog
Files Changed
About the Author: Raphael Malikian — Clinical AI Solutions Architect. I specialise in building and fixing AI/ML systems for healthcare, including vector databases, RAG pipelines, and clinical NLP. If you need help with your project or think I can add value to your organisation, feel free to reach out — I'd love to connect.
📧 rtmalikian@gmail.com
🔗 GitHub: https://github.com/rtmalikian
🔗 LinkedIn: http://www.linkedin.com/in/raphael-t-malikian-mbbs-bsc-hons-71075436a
Disclosure: This code was developed with assistance from DeepSeek-v4-pro (DeepSeek) via Hermes Agent (Nous Research). All changes were reviewed, tested against the actual codebase, and verified for correctness.