The config loading logic in both Config.assign_config and ShipConfig.assign_config checks file existence using Path(path).exists without calling it. Since exists is a method, not calling it results in a truthy method object, which makes the condition always evaluate to True.
This can silently accept invalid paths and later fail during file operations with less clear errors.
Affected Locations
WeatherRoutingTool/config.py
WeatherRoutingTool/ship/ship_config.py
Current pattern:
if Path(path).exists:
with path.open("r") as f:
...
This should call the method:
Why This Matters
- Invalid paths may not be detected early.
- The code may fail later with
FileNotFoundError or AttributeError, making debugging harder.
- The logic does not reliably validate configuration file existence.
Proposed Fix
-
Normalize input using path = Path(path) to support both str and Path.
-
Replace Path(path).exists with path.exists().
-
Raise a clear ValueError if:
path is None when init_mode == "from_json"
- The file does not exist
This keeps behavior unchanged for valid inputs while improving robustness and clarity of error handling.
I am currently working on this fix and will raise a PR shortly.
The config loading logic in both
Config.assign_configandShipConfig.assign_configchecks file existence usingPath(path).existswithout calling it. Sinceexistsis a method, not calling it results in a truthy method object, which makes the condition always evaluate toTrue.This can silently accept invalid paths and later fail during file operations with less clear errors.
Affected Locations
WeatherRoutingTool/config.pyWeatherRoutingTool/ship/ship_config.pyCurrent pattern:
This should call the method:
Why This Matters
FileNotFoundErrororAttributeError, making debugging harder.Proposed Fix
Normalize input using
path = Path(path)to support bothstrandPath.Replace
Path(path).existswithpath.exists().Raise a clear
ValueErrorif:pathisNonewheninit_mode == "from_json"This keeps behavior unchanged for valid inputs while improving robustness and clarity of error handling.
I am currently working on this fix and will raise a PR shortly.