Skip to content

Migrate state, cli_args, and output out of main.py#1893

Merged
rolandwalker merged 1 commit into
mainfrom
RW/shorter-main-py-refactor-20260516
May 16, 2026
Merged

Migrate state, cli_args, and output out of main.py#1893
rolandwalker merged 1 commit into
mainfrom
RW/shorter-main-py-refactor-20260516

Conversation

@rolandwalker
Copy link
Copy Markdown
Contributor

Description

Create a mycli/app_state.py, mycli/cli_args.py, and mycli/output.py, factoring logic out of mycli/main.py, with no functional change.

Like other refactors, this could be seen as incomplete in various ways, but it moves us forward on reducing LOC in main.py (which is now a third of the size from before refactoring started).

Checklist

  • I added this contribution to the changelog.md file.
  • I added my name to the AUTHORS file (or it's already there).
  • To lint and format the code, I ran
    uv run ruff check && uv run ruff format && uv run mypy --install-types .

@rolandwalker rolandwalker self-assigned this May 16, 2026
@rolandwalker rolandwalker force-pushed the RW/shorter-main-py-refactor-20260516 branch from ca45c90 to 81218ed Compare May 16, 2026 17:29
@rolandwalker rolandwalker requested review from amjith and scottnemes May 16, 2026 17:33
Comment thread mycli/output.py Outdated

if TYPE_CHECKING:

def __getattr__(self, name: str) -> Any: ...
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems like it short circuits the mypy checks; was it done to get past errors that were happening? Ran this through Claude and it recommends something like the below instead to prevent future errors not being caught by mypy:

if TYPE_CHECKING:
    from cli_helpers.tabular_output import TabularOutputFormatter
    from configobj import ConfigObj

    class _MyCliState(Protocol):
        # External attributes supplied by the concrete class (MyCli).
        config: ConfigObj
        my_cnf: ConfigObj
        logfile: TextIOWrapper | None
        prompt_session: Any
        prompt_format: str
        prompt_lines: int
        explicit_pager: bool
        ptoolkit_style: Any
        helpers_style: Any
        helpers_warnings_style: Any
        main_formatter: TabularOutputFormatter
        redirect_formatter: TabularOutputFormatter

        # Provided by AppStateMixin.
        def read_my_cnf(self, cnf: ConfigObj, keys: list[str]) -> dict[str, Any]: ...

        # Provided by OutputMixin itself; declared so cross-method calls type-check.
        def log_output(self, output: str | AnyFormattedText) -> None: ...
        def get_output_margin(self, status: str | None = None) -> int: ...
        def get_reserved_space(self) -> int: ...


class OutputMixin:
    def output_timing(self: _MyCliState, timing: str, is_warnings_style: bool = False) -> None:
...

Will approve still in case you do not think that is an issue however.

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.

Thanks! Will try it.

@rolandwalker rolandwalker force-pushed the RW/shorter-main-py-refactor-20260516 branch from 81218ed to d3fb1eb Compare May 16, 2026 21:00
Create a mycli/app_state.py, mycli/cli_args.py, and mycli/output.py,
factoring logic out of mycli/main.py, with no functional change.
@rolandwalker rolandwalker force-pushed the RW/shorter-main-py-refactor-20260516 branch from d3fb1eb to 8bae90a Compare May 16, 2026 22:28
@rolandwalker rolandwalker merged commit c12fdbb into main May 16, 2026
8 checks passed
@rolandwalker rolandwalker deleted the RW/shorter-main-py-refactor-20260516 branch May 16, 2026 22:33
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.

2 participants