Skip to content

Enable SIM108 (ternary operator) for policy code and sweep the codebase #1195

@MImmesberger

Description

@MImmesberger

Blocked by #1156, #1167, #1178 (stacked PRs touching the same files — do the sweep on main after they merge).

Vectorization handles ternary expressions (ttsim.tt.vectorization converts ast.IfExp to xnp.where via _ifexp_to_call), but pyproject.toml ignores SIM108 for src/gettsim/germany/* with the incorrect justification "vectorization requires if/else blocks". Context: #1178 (comment)

Tasks

  • Remove the "SIM108" line from per-file-ignores."src/gettsim/germany/*" in pyproject.toml. Keep "RET" and the other ignores — the return-pattern restrictions are real.

  • Convert all 7 violations to ternaries (list via ruff check --isolated --select SIM108 src/gettsim/germany/):

    • einkommensteuer/abzüge/alleinerziehend.py:14
    • einkommensteuer/abzüge/vorsorge.py:113
    • elterngeld/elterngeld.py:92
    • erziehungsgeld/erziehungsgeld.py:72
    • ids.py:119, ids.py:278
    • kinderbonus/kinderbonus.py:15

    Ruff marks these fixes unsafe because of comments inside branches — apply manually and keep the comments (move them above the assignment). No noqas: ruff already skips sites where the ternary would exceed the line limit.

  • Update docs to recommend ternaries for single-assignment branches (statement if/elif/else remains for nested/multi-branch logic):

    • docs/gettsim_developer/code-restrictions.md (currently only lists one-line if-else as "allowed")
    • AGENTS.md, section "Code Restrictions for Vectorization"

Acceptance criteria

  • pixi run prek run --all-files passes with the ignore removed.
  • Pure refactor: pixi run ty, pixi run ty-jax, and the full test suite (pixi run -e py314-jax tests -n 7) pass unchanged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agentTriaged, scoped, and ready for an autonomous agent to implement

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions