Skip to content

fix: correct type annotations, docstrings, and bare except blocks#912

Open
haoyu-haoyu wants to merge 1 commit intosunlabuiuc:masterfrom
haoyu-haoyu:fix/code-quality-cleanup
Open

fix: correct type annotations, docstrings, and bare except blocks#912
haoyu-haoyu wants to merge 1 commit intosunlabuiuc:masterfrom
haoyu-haoyu:fix/code-quality-cleanup

Conversation

@haoyu-haoyu
Copy link
Copy Markdown
Contributor

Summary

  • Fix torch.tensortorch.Tensor in type annotations across 8 model files (safedrug, gamenet, micron, adacare, retain, grasp, molerec, models/utils). torch.tensor is a constructor function, not a type class — using it as an annotation confuses type checkers and is semantically incorrect. All torch.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: with except Exception: in base_dataset.py (2 occurrences in multiprocessing progress-tracking loops). Bare except: catches KeyboardInterrupt and SystemExit, which prevents users from interrupting long-running dataset processing with Ctrl+C.

Files changed (11)

File Change
pyhealth/trainer.py Docstring fix
pyhealth/datasets/mimic3.py Docstring fix
pyhealth/datasets/base_dataset.py except:except Exception: (×2)
pyhealth/models/safedrug.py torch.tensortorch.Tensor in annotations
pyhealth/models/gamenet.py torch.tensortorch.Tensor in annotations
pyhealth/models/micron.py torch.tensortorch.Tensor in annotations + docstrings
pyhealth/models/adacare.py torch.tensortorch.Tensor in annotations
pyhealth/models/retain.py torch.tensortorch.Tensor in annotations
pyhealth/models/grasp.py torch.tensortorch.Tensor in annotations
pyhealth/models/molerec.py torch.tensortorch.Tensor in annotations
pyhealth/models/utils.py torch.tensortorch.Tensor in annotations

Test plan

  • These are annotation-only and docstring-only changes — no runtime behavior is affected
  • Verified torch.tensor(...) constructor calls are untouched in mixed files (micron.py, grasp.py)
  • Existing tests should pass without modification

- 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant