Skip to content

fix: resolve lifecycle values from Typer context - #364

Open
codeforester wants to merge 2 commits into
mainfrom
bug/356-20260918-typer-lifecycle-context
Open

codeforester wants to merge 2 commits into
mainfrom
bug/356-20260918-typer-lifecycle-context

Conversation

@codeforester

Copy link
Copy Markdown
Contributor

Summary

  • Resolve omitted-context lifecycle lookups from the active Typer-owned Click context, including the vendored context stack.
  • Preserve explicit context lookup and the outside-invocation error.
  • Cover normalized lifecycle values from a nested Typer command.

Closes #356

Validation

  • uv run --extra dev --extra typer --extra quality python -m pytest tests/test_typer_adapter.py tests/test_lifecycle_options.py -q
  • uv run --extra dev --extra typer --extra quality python -m mypy --strict lib/python/base_cli/lifecycle_options.py
  • Ruff check/format and git diff --check

except ImportError:
pass
else:
from ._click_compat import dialect_for_typer

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reuse/altitude: this new Typer-dialect context resolution (private typer import, get_current_context/globals fallback dance) is hand-rolled inline here instead of being added to _click_compat.py, which this codebase already uses as the single place for dialect-crossing/private-Typer-import logic per its own module docstring. The next caller needing "the active context regardless of dialect" will either duplicate this or diverge from it.

@codeforester

Copy link
Copy Markdown
Contributor Author

Additional finding (file not touched by this diff, so not postable as an inline comment):

lib/python/base_cli/_click_compat.py:100_vendored_typer_dialect() reads module.core/module.exceptions outside the try/except that guards the Typer imports, so it can raise an uncaught AttributeError instead of degrading to plain click. Now that get_lifecycle_values() (this PR, lifecycle_options.py:195) calls dialect_for_typer() on every no-context invocation whenever typer is merely importable, a Typer release/environment that exposes typer._click.Command (passing the initial guard) but not the core/exceptions submodules would make a call like base_cli.get_lifecycle_values() blow up with AttributeError instead of the documented RuntimeError, breaking callers that only catch RuntimeError. Worth hardening while touching this code path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: resolve public lifecycle values from the active Typer Click dialect

1 participant