Skip to content

Fix StrictMock stub to use class inheriting from Any instead of alias#373

Open
maggiemoss wants to merge 1 commit intofacebook:mainfrom
maggiemoss:export-D97783042
Open

Fix StrictMock stub to use class inheriting from Any instead of alias#373
maggiemoss wants to merge 1 commit intofacebook:mainfrom
maggiemoss:export-D97783042

Conversation

@maggiemoss
Copy link
Copy Markdown
Contributor

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

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
@meta-cla meta-cla bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Mar 23, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync bot commented Mar 23, 2026

@maggiemoss has exported this pull request. If you are a Meta employee, you can view the originating Diff in D97783042.

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

Labels

CLA Signed Do not delete this pull request or issue due to inactivity. fb-exported meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant