iSpec
iSpec copied to clipboard
Fix: list comprehension scope bug
❗ Problem
This PR fixes an issue where locals() was used inside a list comprehension (in modeling.ssf.model_spectrum, where the script checks that all input variables have the same number of elements).
This issue was throwing KeyErrors whenever the model_spectrum function was called, as list comprehensions have their own local scope (see this Stack Overflow post) so it couldn't find any variables defined outside the comprehension.
🔧 Fix
The fix is very simple -- take a snapshot of the local variables before executing the list comprehension:
- lengths = {name: len(locals()[name]) for name in names}
+ local_snapshot = dict(locals())
+ lengths = {name: len(local_snapshot[name]) for name in names}
With this change, the model_spectrum function runs fine. There are no necessary API changes or changes to other parts of the codebase.