Skip to content

refactor: move processing out of StatementBatch constructor #201

Description

@boscorat

Parent issue

#194 — function purification

Problem

StatementBatch.__init__ (statements.py:1278) is a classic "constructor does too much" anti-pattern. On construction it:

  • Calls validate_or_initialise_project() which creates directories and DB files
  • Calls asyncio.run() / ProcessPoolExecutor for parallel processing
  • Processes all PDFs (writing temp parquet files to disk)
  • Prints timing summaries

You cannot create a StatementBatch object without actually processing PDFs. There is no way to construct one with mock data for testing.

Proposal

Make the constructor a pure data holder. Move processing into a separate process() or run() method. The constructor should store configuration; the method should execute the pipeline.

Code relationships

Target:

  • StatementBatch.__init__()statements.py:1278

Callers (will need updating):

  • StatementBatch.__init__ in conftest.py (test fixture)
  • StatementBatch.__init__ in CLI handler (cli.py)

Related (called from init):

  • validate_or_initialise_project()paths.py
  • process_pdf_statement()statements.py:828
  • StatementBatch.__process_batch_sequential()statements.py:1377
  • StatementBatch.__process_batch_turbo()statements.py:1398

Existing tests:

  • tests/test_statements.py::TestGoodStatements — creates StatementBatch in conftest fixture
  • tests/conftest.py — session fixtures create StatementBatch objects

All existing tests will need updating to call batch.process() after construction.

Siblings

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorcode refactoring

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions