Skip to content

Fix mdiff.py type annotations and remove pyre-fixme suppressions#1362

Open
anushamukka-dev wants to merge 1 commit into
facebook:mainfrom
anushamukka-dev:export-D112392597
Open

Fix mdiff.py type annotations and remove pyre-fixme suppressions#1362
anushamukka-dev wants to merge 1 commit into
facebook:mainfrom
anushamukka-dev:export-D112392597

Conversation

@anushamukka-dev

Copy link
Copy Markdown

Summary:
mdiff.py carried 29 pyre-fixme suppressions, almost all stemming from
two root causes:

  • Functions that operate on diff content were annotated as str (or the
    overly broad Sized) when they actually take bytes. This mislabeling
    forced pyre-fixme[9]/[6] at nearly every internal call site.
  • diffopts populates its option fields dynamically via setattr, so it
    declared none of them; every opts.<field> access tripped
    pyre-fixme[16].

Fixes, matching how the code actually behaves at runtime:

  • wsclean, splitblock, allblocks, and unidiff now take bytes
    (unidiff's a is Optional[bytes], reflecting the existing
    a is None handling for added files).
  • diffopts declares its option fields as class-level attribute
    annotations, so attribute access type-checks without changing the
    setattr-based initialization.
  • _unidiff's return type admits the leading bool sentinel it yields
    (Iterator[Union[bool, ...]]).
  • The two Optional-subscript fixmes are resolved by reading/writing
    through the prev alias, which pyre can prove is non-None, instead of
    the Optional hunk.

All 29 suppressions are removed with no runtime behavior change (the
splitblock and hunk/prev edits are behavior-preserving renames/alias
uses).

Note: diffopts is a concrete class here, so class-level attribute
annotations are used rather than a separate Protocol — this is the minimal
change that makes every opts.<field> access resolve.

Differential Revision: D112392597

Summary:
`mdiff.py` carried 29 `pyre-fixme` suppressions, almost all stemming from
two root causes:

- Functions that operate on diff *content* were annotated as `str` (or the
  overly broad `Sized`) when they actually take `bytes`. This mislabeling
  forced `pyre-fixme[9]`/`[6]` at nearly every internal call site.
- `diffopts` populates its option fields dynamically via `setattr`, so it
  declared none of them; every `opts.<field>` access tripped
  `pyre-fixme[16]`.

Fixes, matching how the code actually behaves at runtime:

- `wsclean`, `splitblock`, `allblocks`, and `unidiff` now take `bytes`
  (`unidiff`'s `a` is `Optional[bytes]`, reflecting the existing
  `a is None` handling for added files).
- `diffopts` declares its option fields as class-level attribute
  annotations, so attribute access type-checks without changing the
  `setattr`-based initialization.
- `_unidiff`'s return type admits the leading `bool` sentinel it yields
  (`Iterator[Union[bool, ...]]`).
- The two `Optional`-subscript fixmes are resolved by reading/writing
  through the `prev` alias, which pyre can prove is non-None, instead of
  the `Optional` `hunk`.

All 29 suppressions are removed with no runtime behavior change (the
`splitblock` and `hunk`/`prev` edits are behavior-preserving renames/alias
uses).

Note: `diffopts` is a concrete class here, so class-level attribute
annotations are used rather than a separate Protocol — this is the minimal
change that makes every `opts.<field>` access resolve.

Differential Revision: D112392597
@meta-cla meta-cla Bot added the CLA Signed label Jul 21, 2026
@meta-codesync

meta-codesync Bot commented Jul 21, 2026

Copy link
Copy Markdown

@anushamukka-dev has exported this pull request. If you are a Meta employee, you can view the originating Diff in D112392597.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant