fix: Python compatibility, safety, and resource management#213
Open
maksimtech wants to merge 1 commit intocnr-isti-vclab:mainfrom
Open
fix: Python compatibility, safety, and resource management#213maksimtech wants to merge 1 commit intocnr-isti-vclab:mainfrom
maksimtech wants to merge 1 commit intocnr-isti-vclab:mainfrom
Conversation
NumPy ≥ 1.24 compatibility (critical)
- Replace all np.bool / np.int / np.float deprecated aliases with
np.bool_ across 6 model files; these were removed in NumPy 1.24
and caused an AttributeError on import with any modern environment.
Bare except: narrowed to specific types (30+ files, 85+ clauses)
- Qt signal UniqueConnection guards: except: → except TypeError
- List.index() guards: except: → except ValueError
- Dict key access: except: → except KeyError
- Numeric conversions in widgets: except: → except (ValueError, ZeroDivisionError)
- OS / file system ops: except: → except OSError / IndexError
- Download failures: bare except re-raised with "from e" to preserve chain
- NewDataset.py os.makedirs try/except replaced with exist_ok=True
Resource leaks fixed (11 files)
- All open() / tarfile.open() / pickle open-write-close patterns
converted to "with" context managers (batch_processing, Project,
MapClassifier, training, dataloaders/helpers, pascal, sbd).
- Removed stale f.close() call after a "with" block in Project.py.
Subprocess shell injection and DEVNULL leaks (install.py, install_conda_windows.py)
- All subprocess.getstatusoutput('string') calls replaced with
subprocess.run(['list'], capture_output=True, text=True) to avoid
implicit shell=True.
- stdout=open(os.devnull, 'wb') replaced with subprocess.DEVNULL
to stop leaking a file descriptor on every check_call invocation.
os.chdir CWD not restored on error (install.py)
- Coraline build wrapped in try/finally to restore the original CWD
even when cmake or make fails, preventing broken relative paths for
the remainder of the install session.
Deprecated PyTorch API (TagLab.py)
- torch.nn.functional.upsample replaced by aliasing to interpolate on
import; existing call sites unchanged.
- Updated stale error message that still referenced CUDA 10.0 / PyTorch
1.0.0 / Python 3.6.8 from 2019.
Add requirements.txt
- Canonical dependency list derived from install.py with pinned lower
bounds and a numpy<2.0 upper cap.
- torch/CUDA installs remain handled by install.py (CUDA-version-aware).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
np.bool/np.int/np.floatdeprecated aliases withnp.bool_across 6 model files. These were removed in NumPy 1.24 and caused anAttributeErroron import in any environment using a modern NumPy (pip default since early 2023).except:clauses across 30+ files to specific exception types (TypeError,ValueError,KeyError,OSError, etc.), preventing accidental swallowing ofSystemExit/KeyboardInterruptand making real errors visible during development.open()/tarfile.open()/ pickle write patterns converted towithcontext managers in 11 files; removed a stalef.close()after awithblock.subprocess.getstatusoutput(string)withsubprocess.run(list, ...)to avoid implicitshell=Trueininstall.pyandinstall_conda_windows.py.stdout=open(os.devnull, 'wb')withsubprocess.DEVNULL— one file descriptor was leaked percheck_callinvocation.os.chdir('coraline')ininstall.pywith save/restore in afinallyblock so the CWD is always restored even when the cmake/make build fails.torch.nn.functional.upsamplewithinterpolate(alias on import); also update the stale 2019 error message referencing CUDA 10.0 / PyTorch 1.0.0 / Python 3.6.8.requirements.txt— canonical dependency list derived frominstall.pywith pinned lower bounds and anumpy<2.0upper cap.Test plan
python -c "import numpy as np; np.bool_"— no AttributeError on NumPy 1.24+install.py cpuon Linux and macOS — confirm clean install without CUDA.datscore files are created and cleaned upconnectProject()work on repeated open/close🤖 Generated with Claude Code