Skip to content

Code health: replace _dw_* setattr side-channel on helper objects with typed state #1931

Closed

Description

@pzfreo

Part of the code-health epic. Evidence pinned to main @ 71b8c94.

Problem

Nine ._dw_* attribute names are bolted onto build123d-drafting-helpers objects through setattr/getattr/hasattr string lookups. There are 34 such sites; _dw_measurement_span alone has 13. Dynamic attribute access in general is heavy: getattr/setattr/hasattr appear 143 times in drawing.py, 103 in from_model.py and 92 in _common.py. This state has no types, mypy cannot see it, and it depends on objects we do not own tolerating extra attributes.

Proposal

Keep this metadata in a typed side table instead. The options are an entry on the registry keyed by annotation identity, or a field on the compiled-plan item. Then remove the _dw_* attributes.

Acceptance

  • grep -rn '_dw_' src returns nothing.
  • A test fails if a _dw_* string reappears.

2026-09-30 remaining family audit

On the reviewed local follow-up aggregate at 9c574776, _dw_spec is the only remaining _dw_* field: 38 source matches across 13 files; tests have 158 matches across 35 files. The registry now snapshots named dimension construction evidence, but the live annotation still carries _dw_spec for precommit ink/interior placement and for repair, lint, evaluation, and raw PDF fallback. The acceptance search for zero _dw_ has not passed.

A final removal needs a coordinated boundary change: carry a typed transient spec through placement, commit named evidence to the registry, then make finished-drawing consumers read that registry record. Preserve raw helper fallback and late Draft PDF styling. This is a planning estimate of 150–300 source lines and 150–250 test lines from the reference map, not a verified patch size. Require registration/rollback, repair, lint/evaluation, PDF/export, and successful drawing/trace parity gates; avoid another persistent cache. No ADR wording change is proposed.

2026-09-30 reviewed local completion candidate

An isolated typed-owner slice at b290233f (integrated locally after the next unpublished aggregate as 0460f23c) makes rg '_dw_' src return no matches and adds a load-bearing guard against reintroduction. Engine-created dimensions now carry a typed transient placement spec on an owned Dimension subclass; the registry snapshots committed named evidence, and lint/repair/evaluation/PDF consumers read registry evidence for named annotations. A fresh reviewer found and reproduced two unnamed place_dim regressions, which were fixed with transient fallback for unnamed dimensions while named missing specs remain fail-closed. The reviewer re-ran both repros and reported no remaining P0–P2 finding. Static, unit, smoke, 451 focused tests, 17 CAD plus three STEP exact parity, and SVG/DXF/PDF/PNG byte parity passed on the isolated slice or its corrected head; the final integrated full fast tier, measured no-regression gate, PR CI, and merge are outstanding. The owned subtype preserves isinstance(helpers.Dimension) and the visible Dimension type name, but exact Python class identity changes; this P3 compatibility risk is disclosed for review. Do not close this issue until the final gates and merge.

2026-09-30 final local verification (unpublished)

The integrated candidate 0f9534c9 retains zero _dw_ source matches and the load-bearing reintroduction guard. Fresh independent integrated and final-delta reviews found no blocking issue. scripts/pr-check --static exited 0; the exact-head fast tier passed 9,938 tests (9 skipped, 15 xfailed), with 96.03% total and 98% changed-line coverage (205/208). The final 14 CAD + three STEP drawing/lint/decision/trace corpus is byte-identical to the #2104 baseline, and five quiet paired workloads showed no reproducible timing regression. Two construction-count guards were moved to the owned Dimension constructor with positive-count preconditions after the first full run exposed their stale _core.Dimension patch site. The source acceptance is met locally, but this issue remains open until a PR passes current-head CI and merges. GitHub branch/PR writes are rejected by automatic approval policy never; no new PR or CI has started.

Activity

  1. added
    tech-debtInternal maintainability or refactoring work
    area:typesTyping and static analysis hygiene
    on Sep 28, 2026
  2. pzfreo commented on Sep 28, 2026

    @pzfreo
    OwnerAuthor

    First typed-state slice merged in #1957: section cutting-plane cut/view identity now lives in immutable SectionMark records owned by AnnotationRegistry, with replacement, clear, snapshot, rollback, and deferred replay tests. The remaining _dw_* metadata is still open under this issue. Fresh review cleared; CI green; full local failures matched untouched main exactly.

  3. pzfreo commented on Sep 29, 2026

    @pzfreo
    OwnerAuthor

    Next typed-state slice: #2099 is open against the reviewed #2084 stack tip. Solved candidate-region provenance now lives in AnnotationRegistry rather than _dw_candidate_region attributes on helper objects; placement, layout comparison, and structural lint read the typed registry state, and replacement/snapshot/reapply follow registry identity. Exact 14 CAD + 3 STEP drawing/lint/decision/trace parity, 234 focused tests, static checks, and a load-bearing mutation passed; a fresh independent review found no actionable findings and reran 215 focused tests. Required GitHub CI is pending. Other _dw_* metadata families remain open.

  4. pzfreo commented on Sep 30, 2026

    @pzfreo
    OwnerAuthor

    Completed in #2105 (merged as f4aa321). On merged main, rg -n "dw" src/draftwright --glob "*.py" returns no matches; the reintroduction guard, independent reviews, and current-head CI (17 successful checks, two expected skips) passed. No ADR text changed.

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

    area:typesTyping and static analysis hygienetech-debtInternal maintainability or refactoring work

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions