Skip to content

fix: undefined names in Python error paths - #6075

Open
Anai-Guo wants to merge 1 commit into
acts-project:mainfrom
Anai-Guo:fix-detray-python-undefined-names
Open

Anai-Guo wants to merge 1 commit into
acts-project:mainfrom
Anai-Guo:fix-detray-python-undefined-names

Conversation

@Anai-Guo

Copy link
Copy Markdown

Fixes five NameErrors in Python code that only runs on error or optional paths, so they were never hit in normal use or CI. In each case the intended behaviour (log + exit, handle the NVML failure, raise a clear argument error, write to stdout) was replaced by a NameError.

file problem fix
Detray/tests/tools/python/options/common_options.py --logfile path uses os.path / os.mkdir, but os is not imported import os
Detray/tests/tools/python/options/plotting_options.py unknown --output_format logs {out_format} (undefined) before sys.exit(1) use args.output_format
Detray/tests/tools/python/propagation_benchmarks.py except NVMLError — name never imported, so an NVML failure raises NameError from inside the handler except nvidia_smi.NVMLError (nvidia_smi does from pynvml import *)
Detray/codegen/detray-sympy/detray_sympy/output.py write_out_file(code) with no file name writes to sys.stdout, but sys is not imported import sys
Python/Examples/python/odd.py getOpenDataDetector(gen3=True, misaligned=True) raises undefined InvalidArgumentError ValueError

Found with pyflakes. Verified by calling each function on the failing path, before and after:

before                                              after
common_options logfile: NameError 'os'              OK
plotting bad format:    NameError 'out_format'      SystemExit 1
write_out_file stdout:  NameError 'sys'             OK
nvml failure path:      NameError 'NVMLError'       handled (prints the NVML error)

(nvidia_smi.NVMLError checked against the nvidia-ml-py3 package: resolves to pynvml.NVMLError.) odd.py was reformatted by black 26.5.1, which collapsed the raise onto one line.

🤖 Generated with Claude Code

Each of these only runs on an error/optional path, so it raised
NameError instead of doing what the code intended:

- Detray options/common_options.py: `os` used for --logfile but not imported
- Detray options/plotting_options.py: log message used undefined `out_format`
- Detray propagation_benchmarks.py: `except NVMLError` (never imported);
  use `nvidia_smi.NVMLError`
- detray_sympy/output.py: `sys.stdout` used without importing `sys`
- Python/Examples/python/odd.py: raised undefined `InvalidArgumentError`;
  use `ValueError`

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added this to the next milestone Sep 13, 2026
@github-actions github-actions Bot added the Component - Detray Affects the Detray project label Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component - Detray Affects the Detray project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant