Remove context manager, inline initialization into __call__#88
Merged
Conversation
- Remove __enter__/__exit__ from both MILC and MILCInterface - Rename _inside_context_manager to _initialized - Inline initialization logic (colorama, arg parsing, config merge, logging setup) directly into __call__() - Preserve error handling: catch non-SystemExit/KeyboardInterrupt exceptions, log them, and sys.exit(255) - Update guard error messages to reference cli() instead of "with statement" - Update setup_logging docstring - Remove unused TracebackType and Type imports - Regenerate API docs Agent-Logs-Url: https://github.com/clueboard/milc/sessions/23594391-a2b0-4db3-9323-cbbbe10f4ba2 Co-authored-by: skullydazed <9553982+skullydazed@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
skullydazed
April 19, 2026 06:46
View session
skullydazed
reviewed
Apr 19, 2026
Agent-Logs-Url: https://github.com/clueboard/milc/sessions/9cffca2c-76c8-4bb4-a570-e23a5867d0bc Co-authored-by: skullydazed <9553982+skullydazed@users.noreply.github.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
Removes the context manager protocol (
__enter__/__exit__) from bothMILCandMILCInterface, inlining the initialization logic directly into__call__(). The_inside_context_managerflag is renamed to_initializedand set toTrueat the start of__call__()instead of inside__enter__().This was discussed in the issue — the context manager added complexity without providing meaningful value, since
__call__()already wrapped itself inwith self:when the context manager hadn't been entered.Changes
milc/milc.py:_inside_context_manager→_initialized__enter__()initialization (colorama, arg parsing, config merge, interactive flag, logging setup) into__call__()with self:recursive call with a simple guard checkRuntimeErrorifcli()is called twice__exit__()error handling: unhandled exceptions (exceptSystemExit/KeyboardInterrupt) are logged and triggersys.exit(255)__enter__()and__exit__()methodssetup_logging()docstringTracebackTypeandTypeimportsmilc/milc_interface.py:__enter__()and__exit__()delegation methodsmilc_options()guard to use_initializedTracebackTypeandTypeimportsdocs/: Regenerated API docsTesting
All 108 existing tests pass. Formatting (yapf) and linting (ruff) are clean. CodeQL reports no security issues.