Fix mdiff.py type annotations and remove pyre-fixme suppressions#1362
Open
anushamukka-dev wants to merge 1 commit into
Open
Fix mdiff.py type annotations and remove pyre-fixme suppressions#1362anushamukka-dev wants to merge 1 commit into
anushamukka-dev wants to merge 1 commit into
Conversation
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
|
@anushamukka-dev has exported this pull request. If you are a Meta employee, you can view the originating Diff in D112392597. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
mdiff.pycarried 29pyre-fixmesuppressions, almost all stemming fromtwo root causes:
str(or theoverly broad
Sized) when they actually takebytes. This mislabelingforced
pyre-fixme[9]/[6]at nearly every internal call site.diffoptspopulates its option fields dynamically viasetattr, so itdeclared none of them; every
opts.<field>access trippedpyre-fixme[16].Fixes, matching how the code actually behaves at runtime:
wsclean,splitblock,allblocks, andunidiffnow takebytes(
unidiff'saisOptional[bytes], reflecting the existinga is Nonehandling for added files).diffoptsdeclares its option fields as class-level attributeannotations, so attribute access type-checks without changing the
setattr-based initialization._unidiff's return type admits the leadingboolsentinel it yields(
Iterator[Union[bool, ...]]).Optional-subscript fixmes are resolved by reading/writingthrough the
prevalias, which pyre can prove is non-None, instead ofthe
Optionalhunk.All 29 suppressions are removed with no runtime behavior change (the
splitblockandhunk/prevedits are behavior-preserving renames/aliasuses).
Note:
diffoptsis a concrete class here, so class-level attributeannotations are used rather than a separate Protocol — this is the minimal
change that makes every
opts.<field>access resolve.Differential Revision: D112392597