Skip to content

Conversation

@George-Ogden
Copy link

The MagicMixin does a lot of things that weren't documented.
It also doesn't override the constructor.

@George-Ogden
Copy link
Author

The tests fail because these methods don't exist on the class - they are added to the instance at runtime.

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

xarray (https://github.com/pydata/xarray)
+ xarray/tests/test_backends_file_manager.py: note: In function "test_file_manager_mock_write":
+ xarray/tests/test_backends_file_manager.py:39: error: "Callable[[VarArg(Any), KwArg(Any)], MagicMock]" has no attribute "assert_has_calls"  [attr-defined]
+ xarray/tests/test_backends_file_manager.py: note: At top level:

zulip (https://github.com/zulip/zulip)
+ zerver/tests/test_push_notifications.py:2402: error: "Callable[[], Literal[True]]" has no attribute "return_value"  [attr-defined]

aiohttp-devtools (https://github.com/aio-libs/aiohttp-devtools)
+ tests/test_runserver_watch.py:46: error: "Callable[[VarArg(Any), KwArg(Any)], MagicMock]" has no attribute "side_effect"  [attr-defined]

aiohttp (https://github.com/aio-libs/aiohttp)
+ aiohttp/test_utils.py:573:5: error: Cannot assign to a method  [method-assign]
+ aiohttp/test_utils.py:573:5: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-method-assign for more info
+ aiohttp/test_utils.py:574:5: error: Cannot assign to a method  [method-assign]
+ aiohttp/test_utils.py:574:23: error: Incompatible types in assignment (expression has type "Callable[[Any, str, Any], None]", variable has type "Callable[[VarArg(Any), KwArg(Any)], MagicMock]")  [assignment]

@George-Ogden
Copy link
Author

George-Ogden commented Nov 21, 2025

Subclassing Any means that this isn't much of an issue

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant