fix: correct type annotations, docstrings, and bare except blocks#912
Open
haoyu-haoyu wants to merge 1 commit intosunlabuiuc:masterfrom
Open
fix: correct type annotations, docstrings, and bare except blocks#912haoyu-haoyu wants to merge 1 commit intosunlabuiuc:masterfrom
haoyu-haoyu wants to merge 1 commit intosunlabuiuc:masterfrom
Conversation
- Fix `torch.tensor` → `torch.Tensor` in type annotations and docstrings across 8 model files (safedrug, gamenet, micron, adacare, retain, grasp, molerec, models/utils). `torch.tensor` is a constructor function, not a type — `torch.Tensor` is the correct class for annotations. - Fix copy-paste docstring errors: - `Trainer.load_ckpt`: "Saves" → "Loads" the model checkpoint - `MIMIC3Dataset.__init__`: "MIMIC4Dataset" → "MIMIC3Dataset" - Replace bare `except:` with `except Exception:` in `base_dataset.py` (2 occurrences). Bare except catches `KeyboardInterrupt` and `SystemExit`, preventing users from interrupting long-running dataset processing.
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.
Summary
Fix
torch.tensor→torch.Tensorin type annotations across 8 model files (safedrug,gamenet,micron,adacare,retain,grasp,molerec,models/utils).torch.tensoris a constructor function, not a type class — using it as an annotation confuses type checkers and is semantically incorrect. Alltorch.tensor(...)function calls are left untouched.Fix copy-paste docstring errors:
Trainer.load_ckpt: docstring said "Saves the model checkpoint" — corrected to "Loads"MIMIC3Dataset.__init__: docstring said "Initializes the MIMIC4Dataset" — corrected to "MIMIC3Dataset"Replace bare
except:withexcept Exception:inbase_dataset.py(2 occurrences in multiprocessing progress-tracking loops). Bareexcept:catchesKeyboardInterruptandSystemExit, which prevents users from interrupting long-running dataset processing with Ctrl+C.Files changed (11)
pyhealth/trainer.pypyhealth/datasets/mimic3.pypyhealth/datasets/base_dataset.pyexcept:→except Exception:(×2)pyhealth/models/safedrug.pytorch.tensor→torch.Tensorin annotationspyhealth/models/gamenet.pytorch.tensor→torch.Tensorin annotationspyhealth/models/micron.pytorch.tensor→torch.Tensorin annotations + docstringspyhealth/models/adacare.pytorch.tensor→torch.Tensorin annotationspyhealth/models/retain.pytorch.tensor→torch.Tensorin annotationspyhealth/models/grasp.pytorch.tensor→torch.Tensorin annotationspyhealth/models/molerec.pytorch.tensor→torch.Tensorin annotationspyhealth/models/utils.pytorch.tensor→torch.Tensorin annotationsTest plan
torch.tensor(...)constructor calls are untouched in mixed files (micron.py,grasp.py)