Pyrefly should support common mocking patterns better
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 519
- PR merge metrics
- No merged PRs in 30d
Description
### Describe the Bug
Pyre had a special hook that allowed arbitrary Callable and BoundMethod types to be used as if they had attributes assert_called_once, assert_called_once_with, assert_not_called, assert_any_call, assert_has_calls, reset_mock.
The rationale for this is that it's very common for unit tests to override the stated attribute types with mocks, and we can potentially get large numbers of low-value type errors downstream. The specific details of mocking patterns (in particular, overriding an explicitly typed attribute on an existing class) means that just directly tracking Mock types doesn't really help here, which is probably why Pyre chose the approach it did.
[Here's a Sandbox example
](https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeS4ATrgLYAEAruhAC4vwuE24DGA1nQg1iuSizoBZXnwA66OXJ5RUcOHQDKMSgDcIPGIjl1jdTDDB0wMFjwAWACjgwoYADR0%2BMUojpwWlAEo6AFoAPkF0FkN0E1i6SmsGShiABgV5dCUVNQAVDk0dPQMjEzMLAH1yiGYWSsdnMCCwugA5XHRimLjjJxdCJ0L9HwLdfToAXklpR2IYHnGRooD0uTK6dj9yqxsHJvC2jujYuAZsACs58Um8v0X9e2WuntOLnk4B0ZhCbbt7GRBUNgeP9HscXpd%2BlpPt9rHZCNktLUeKgoLBMOV2vdQSYTucIR8ijCdvDVIjysjUTB0ZiYOUAO6sBz-QHAkABECuEBkBJgKCkQgsWhQCgAYjoAAVSDy%2Bb4MDgCHQeO1IABzJKoFgQdqEORizQwOi2NjEOCIAD0Zu55j5hFEKrNMHQZswvDgZqV6FV6s17TNllEdFQ2lQ0EBsEVyogasoGq1MVwxB96DgOvQZBYtnawW0WjgcYmdH%2BAGZCABGABM-zkAG0tNRKHAALpyJhCERiKnBTAQBJvCA5gsAcij6FEMEHclHLGCCQAjgwe53PKRgqgePpVEO6ahkhP0CAAL6cteanMAMWgMAoaCweCIZEPQA) of the kind of code we handle much worse than Pyre did.
I don't have strong feelings about the exact logic we should use to reduce noise (it may be good to investigate other type checkers in the interest of compatibility) but we should try to make Pyrefly less noisy on tests
Contributor guide
Assessment
This issue has not been assessed yet.