Conversation
|
static_analyzer -> analyzer? Since we rename it to analyzer in src/ |
|
|
||
| # Resolution — read directly from the config object. | ||
| # No inference or reverse mapping — display what the config contains. | ||
| _ref_config = config_obj if not module else (configs[0] if configs else None) |
Check failure
Code scanning / CodeQL
Potentially uninitialized local variable Error
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 3 months ago
In general, this class of problem is fixed by ensuring the variable is definitely assigned on all code paths before its first use, or by guarding its use so that it is never read when uninitialized. For Python, another option is to rely on a non-local or global binding, but that would change the intended scope; here, configs is clearly meant to be a local variable representing some configuration list.
The single best way to fix this without changing the existing functionality is to avoid depending on configs when it might not exist, because its only use here is to obtain a reference configuration when module is truthy. In the provided code, _ref_config is set with:
_ref_config = config_obj if not module else (configs[0] if configs else None)This line both references configs and implicitly assumes it is defined. A safe and behavior-preserving change is to first initialize _ref_config to config_obj, then, only if module is true and configs is known to exist, override _ref_config from configs[0]. We can do this by:
- Setting
_ref_config = config_objunconditionally. - Wrapping the override in a
try/except NameErrorblock (or another guard) so that ifconfigswas not defined earlier in the function, the NameError is caught and_ref_configsimply remainsconfig_obj.
This keeps the existing intent—use configs[0] when in module mode and configs is available—while guaranteeing that line 422 no longer directly references an uninitialized local. All changes are localized to the small region around lines 420–423 in src/winml/modelkit/commands/config.py, and no new imports or helpers are required.
| @@ -419,7 +419,14 @@ | ||
|
|
||
| # Resolution — read directly from the config object. | ||
| # No inference or reverse mapping — display what the config contains. | ||
| _ref_config = config_obj if not module else (configs[0] if configs else None) | ||
| _ref_config = config_obj | ||
| if module: | ||
| # In module mode, prefer the first entry from `configs` if available. | ||
| try: | ||
| _ref_config = configs[0] if configs else None | ||
| except NameError: | ||
| # `configs` was never initialized on this code path; fall back to `config_obj`. | ||
| pass | ||
| if _ref_config is not None: | ||
| _quant = _ref_config.quant | ||
|
|
cc21402 to
3b3cc65
Compare
ede2514 to
efb372e
Compare
…t/perf enhancements CLI Arguments: - Shared decorator module (_options.py) for -m, -d, --ep, -o, -t, -p - Global-only -v/-q verbosity (ADR-2), mutual exclusion - Standardized --device (auto|cpu|gpu|npu, case-insensitive) across 8 commands - --precision as string+validator for forward-compat (ADR-8) - --no-X negation convention (ADR-10) - 19 spec enforcement tests + 43 import-time regression tests Performance: - Lazy imports — 88x startup speedup (37s to 0.4s) - Break circular import onnx↔compiler↔session with lazy __getattr__ Features: - Build: StageLive Rich progress, EP bar animation, summary sections - Eval: Rich console display, EPContext support - Inspect: I/O extraction consolidation, --list-tasks - Perf: resolved device/task/IO tensor display, ONNX monitor fix - Analyzer: optim registry integration, EP pass-through - Config: registry short-circuit, fusion flag cleanup Fixes: - torch.device coercion in session - QNN compiler output suppression - ORT pre-process metadata injection - Warning suppression for transformers/torch - EP re-registration log level (warning→debug) - External data sidecar cleanup in optim pipes
Summary
Port of mvp/main work to gh/main (13 commits, squashed from 44 originals).
Features
_options.py), global-only-v/-q, standardized--device/--ep/-m/-o/-t/-pacross all 11 subcommands (10 ADRs indocs/design/cli/3_cli_args_spec.md)winml --help)Fixes
onnx ↔ compiler ↔ sessionbroken with lazy__getattr__torch.devicecoercion in sessionTests
test_cli_spec.py)test_import_time.py)