Fix dead-code env-var override notice in `open_root_actor`

The `TRACTOR_LOGLEVEL`/`TRACTOR_SPAWN_METHOD` override-notice
branches were unreachable: `loglevel`/`start_method` were
reassigned to the env value BEFORE the `!=` compare, so the
"OVERRIDES caller-passed" message never fired. Capture the
caller value first, then compare. Rel. `208e7c09`/`d4eac06d`
"Honor env-vars" (`trionics.start_or_cancel`); surfaced by
`/code-review high` on #462.

(this patch was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
trionics_start_or_cancel
Gud Boi 2026-06-17 19:46:43 -04:00
parent fdac157d3d
commit b0ac681245
1 changed files with 13 additions and 6 deletions

View File

@ -290,6 +290,10 @@ async def open_root_actor(
# console verbosity without touching application code. # console verbosity without touching application code.
env_ll_report: str = '' env_ll_report: str = ''
if env_ll := os.environ.get('TRACTOR_LOGLEVEL'): if env_ll := os.environ.get('TRACTOR_LOGLEVEL'):
# capture the caller-passed value BEFORE the env-var
# clobbers it, else the override-notice below is dead
# code (the `!=` compare is always `False`).
caller_ll: str|None = loglevel
loglevel = env_ll loglevel = env_ll
env_ll_report: str = ( env_ll_report: str = (
f'Detected env-var setting,\n' f'Detected env-var setting,\n'
@ -299,14 +303,14 @@ async def open_root_actor(
f'loglevel={loglevel!r}\n' f'loglevel={loglevel!r}\n'
) )
if ( if (
loglevel caller_ll
and and
loglevel.upper() != env_ll.upper() caller_ll.upper() != env_ll.upper()
): ):
env_ll_report += ( env_ll_report += (
f'\n' f'\n'
f'NOTE env-var OVERRIDES caller-passed,\n' f'NOTE env-var OVERRIDES caller-passed,\n'
f'loglevel={loglevel!r}\n' f'loglevel={caller_ll!r}\n'
) )
loglevel: str = ( loglevel: str = (
@ -332,6 +336,9 @@ async def open_root_actor(
# the `examples/debugging/<script>.py` suite under each # the `examples/debugging/<script>.py` suite under each
# backend from `tests/devx/conftest.py::spawn`). # backend from `tests/devx/conftest.py::spawn`).
if env_sm := os.environ.get('TRACTOR_SPAWN_METHOD'): if env_sm := os.environ.get('TRACTOR_SPAWN_METHOD'):
# capture the caller-passed value BEFORE the env-var
# clobbers it (else the override-notice is dead code).
caller_sm: str|None = start_method
start_method: str = env_sm start_method: str = env_sm
env_sm_report: str = ( env_sm_report: str = (
f'Detected env-var setting,\n' f'Detected env-var setting,\n'
@ -341,15 +348,15 @@ async def open_root_actor(
f'start_method={env_sm!r}\n' f'start_method={env_sm!r}\n'
) )
if ( if (
start_method caller_sm
and and
start_method != env_sm caller_sm != env_sm
): ):
_log.warning( _log.warning(
env_sm_report env_sm_report
+ +
f'NOTE env-var OVERRIDES caller-passed,\n' f'NOTE env-var OVERRIDES caller-passed,\n'
f'`start_method={start_method!r}`\n' f'`start_method={caller_sm!r}`\n'
) )
else: else:
_log.info(env_sm_report) _log.info(env_sm_report)