Fix StrictMock stub to use class inheriting from Any instead of alias#373
Open
maggiemoss wants to merge 1 commit intofacebook:mainfrom
Open
Fix StrictMock stub to use class inheriting from Any instead of alias#373maggiemoss wants to merge 1 commit intofacebook:mainfrom
maggiemoss wants to merge 1 commit intofacebook:mainfrom
Conversation
Summary: The StrictMock type stubs across strictmock and testslide defined `StrictMock = Any`, making it a type alias for `Any`. Pyrefly treats bare `Any` as non-instantiable, causing ~14,700 `bad-instantiation` errors (`Any cannot be instantiated`) across ~3,500 test files in fbcode. Additionally, when the stub was changed to a plain `class StrictMock`, Pyrefly correctly flagged ~13,500 `bad-argument-type` errors where `StrictMock` instances were passed to functions expecting specific types — which is the intended usage of StrictMock as a mock stand-in. The fix changes all four stub files from: ``` StrictMock = Any ``` to: ``` class StrictMock(Any): ... ``` This makes StrictMock an instantiable class that inherits from Any, so it is both constructible and assignable to any type — matching its real-world usage as a universal mock object. Affected stubs: - fbcode/strictmock/strict_mock.pyi - fbcode/testslide/testslide/strict_mock.pyi - fbcode/python/typeshed_internal/testslide/core/strict_mock.pyi - fbcode/python/typeshed_experimental/testslide/core/strict_mock.pyi Differential Revision: D97783042
|
@maggiemoss has exported this pull request. If you are a Meta employee, you can view the originating Diff in D97783042. |
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:
The StrictMock type stubs across strictmock and testslide defined
StrictMock = Any, making it a type alias forAny. Pyrefly treats bareAnyas non-instantiable, causing ~14,700bad-instantiationerrors (Any cannot be instantiated) across ~3,500 test files in fbcode.Additionally, when the stub was changed to a plain
class StrictMock, Pyrefly correctly flagged ~13,500bad-argument-typeerrors whereStrictMockinstances were passed to functions expecting specific types — which is the intended usage of StrictMock as a mock stand-in.The fix changes all four stub files from:
to:
This makes StrictMock an instantiable class that inherits from Any, so it is both constructible and assignable to any type — matching its real-world usage as a universal mock object.
Affected stubs:
Differential Revision: D97783042