fix: replace bare except with specific exception types (Fixes #1173)#1174
Open
rtmalikian wants to merge 1 commit into
Open
fix: replace bare except with specific exception types (Fixes #1173)#1174rtmalikian wants to merge 1 commit into
rtmalikian 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.