Skip to content

validate_implementations.py: fix type-safety diagnostics #117

Closed

Description

@neuromechanist

Static analysis (Pyright) flags real issues in validate_implementations.py:

  1. run_fortran_amica is typed -> Dict but returns None on several early-exit
    paths (binary missing, non-zero return code, timeout, exception). Callers
    already handle this (compare_results(fortran_results: Optional[Dict], ...)),
    so the annotation is just wrong. Fix: -> Optional[Dict].
  2. Inside run_fortran_amica, import os and original_dir = os.getcwd() happen
    inside the try: block; the except branches reference both, so Pyright
    correctly flags them as possibly-unbound if the import itself ever failed.
    Fix: hoist import os to the top-level imports and set original_dir before
    the try:.
  3. load_eeglab_data(..., dtype: np.dtype = np.float32) in
    pyAMICA/torch_impl/utils.py has a default value that does not match its own
    annotation (np.float32 is a scalar type, not an np.dtype instance). Fix:
    widen the annotation (e.g. npt.DTypeLike).

Verified NOT real bugs (false positives, no fix needed): the Import "torch" /
Import "scipy.optimize" could not be resolved diagnostics are a Pyright/IDE
environment issue -- both import and run fine under uv run python -c "import torch, scipy". Leaving those as-is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions