Skip to content

Centralize duplicated cross-mixin TYPE_CHECKING property stubs #834

Description

@tschm

Summary

src/jquantstats/_portfolio_cost.py and src/jquantstats/_portfolio_attribution.py each carry their own if TYPE_CHECKING: block of read-only @property stubs describing attributes that are actually defined on sibling mixins (so each mixin type-checks in isolation). The same names are declared in more than one place, which is duplicated boilerplate that can drift.

These stubs were introduced to satisfy mypy --strict (consistent read-only property declarations across the mixins that compose Portfolio).

Where

  • src/jquantstats/_portfolio_cost.pyTYPE_CHECKING block with @property stubs: data, returns, turnover, profit
  • src/jquantstats/_portfolio_attribution.py — overlapping TYPE_CHECKING stubs (e.g. returns, nav_accumulated, assets, data)

Proposed change

Hoist a single shared declaration — e.g. a PortfolioLike-style Protocol (matching the pattern already used in _reports/_protocol.py, _plots/_protocol.py, _utils/_protocol.py) or one shared TYPE_CHECKING base — that the cost/attribution mixins reference instead of each re-declaring the cross-mixin attributes.

Acceptance criteria

  • The per-mixin TYPE_CHECKING stub blocks are replaced by one shared declaration.
  • No behavior change (the stubs are type-only).
  • make typecheck (both ty and mypy --strict) stays green.
  • make test stays green at 100% coverage.

Context

Surfaced by a Rhiza quality assessment — the only locally-owned item below 10 (Code structure & readability, 9→10). Low effort, no runtime impact.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions