Skip to content

Normalize annotation-independent method headers in ClassBodyNormalForm - #646

Merged
trissim merged 1 commit into
mainfrom
fix/method-annotation-normalized-overrides
Nov 28, 2026
Merged

trissim merged 1 commit into
mainfrom
fix/method-annotation-normalized-overrides

Conversation

@trissim

@trissim trissim commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Why

On the 540-file comms-tui (src/toad) scan, SiblingOverrideDetector returned 0 findings and RestatedOverrideDetector returned 0 findings — missing identical @property and concrete method overrides across Qt and Textual siblings (ConversationPager.selected_categories, QuestionContext.question, SnapshotPresentation.commit_claim, BlockCursor.move, Page.shown, FrozenClosedHistory.latest, etc.).

Root cause at nominal_refactor_advisor/class_index.py:4759:
ClassBodyNormalForm._normalized_method stripped leading docstrings and receiver type-narrowing aliases, but left parameter and return annotations in the normalized AST and free-name bindings. Two identical concrete methods where one omitted -> ... (QtConversationHistory.selected_categories) and the other declared -> frozenset[type[MessageCategory]] (ConversationHistory.selected_categories), or where each annotated its own class (-> QtQuestion vs -> Question), hashed to different digests and failed same_declaration_as.

Fix

  • ClassBodyNormalForm._strip_method_header_annotations (nominal_refactor_advisor/class_index.py:4779): shallow-copy method parameters and clear parameter/return annotations when every decorator on the method is annotation-independent (property, cached_property, classmethod, staticmethod, override, final, or none). @abstractmethod, @overload, and custom/unmodeled decorators keep their signatures intact so contract widenings like ActivatesContract.activate() -> None vs Activates.activate() -> object are never conflated.
  • SiblingOverrideMove.select_lifted_index (nominal_refactor_advisor/refactors/sibling_overrides.py:828): when lifting siblings that differ only by omitted annotations, prefer the most-annotated sibling whose annotation imports move cleanly without closing a cycle (so ConversationPager.selected_categories preserves -> frozenset[type[MessageCategory]]). When siblings declare conflicting annotations on the same header slot (-> QtQuestion vs -> Question), refuse blind lifting with NeededInput.SOURCE_CHANGE.
  • RestatedOverrideDeletion._require_inherited_preserves_annotations (nominal_refactor_advisor/refactors/restated_overrides.py:944): allow deleting an unannotated or matching-annotation override automatically, while refusing to silently drop annotations that the subclass declares and the inherited method lacks (FrozenClosedHistory.latest over unannotated ClosedHistory.latest).

Live Toad Impact (src/toad, 540 files)

  • SiblingOverrideDetector: 0 -> 13 real findings (including ConversationPager.selected_categories as executable_candidate lifting cleanly with -> frozenset[type[MessageCategory]] preserved, and QtQuestion/Question QuestionContext.question).
  • RestatedOverrideDetector: 0 -> 1 real finding (FrozenClosedHistory.latest), with Activates.activate (@abstractmethod) cleanly excluded.

Proof

  • Added 5 regression tests in tests/test_sibling_overrides.py and tests/test_restated_overrides.py.
  • REL_IMPORTS=0.

@trissim
trissim merged commit 7340987 into main Nov 28, 2026
2 of 10 checks passed
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.

1 participant