-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fix @patch when new
is missing
#10459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Diff from mypy_primer, showing the effect of this PR on open source code: streamlit (https://github.com/streamlit/streamlit)
- lib/tests/streamlit/config_test.py:619:9: error: "_patch[Union[MagicMock, AsyncMock]]" has no attribute "return_value" [attr-defined]
+ lib/tests/streamlit/config_test.py:619:9: error: "_patch_default_new" has no attribute "return_value" [attr-defined]
- lib/tests/streamlit/config_test.py:621:9: error: "_patch[Union[MagicMock, AsyncMock]]" has no attribute "side_effect" [attr-defined]
+ lib/tests/streamlit/config_test.py:621:9: error: "_patch_default_new" has no attribute "side_effect" [attr-defined]
- lib/tests/streamlit/config_test.py:645:9: error: "_patch[Union[MagicMock, AsyncMock]]" has no attribute "return_value" [attr-defined]
+ lib/tests/streamlit/config_test.py:645:9: error: "_patch_default_new" has no attribute "return_value" [attr-defined]
- lib/tests/streamlit/config_test.py:647:9: error: "_patch[Union[MagicMock, AsyncMock]]" has no attribute "side_effect" [attr-defined]
+ lib/tests/streamlit/config_test.py:647:9: error: "_patch_default_new" has no attribute "side_effect" [attr-defined]
- lib/tests/streamlit/config_test.py:683:9: error: "_patch[Union[MagicMock, AsyncMock]]" has no attribute "return_value" [attr-defined]
+ lib/tests/streamlit/config_test.py:683:9: error: "_patch_default_new" has no attribute "return_value" [attr-defined]
- lib/tests/streamlit/config_test.py:685:9: error: "_patch[Union[MagicMock, AsyncMock]]" has no attribute "side_effect" [attr-defined]
+ lib/tests/streamlit/config_test.py:685:9: error: "_patch_default_new" has no attribute "side_effect" [attr-defined]
- lib/tests/streamlit/config_test.py:731:9: error: "_patch[Union[MagicMock, AsyncMock]]" has no attribute "return_value" [attr-defined]
+ lib/tests/streamlit/config_test.py:731:9: error: "_patch_default_new" has no attribute "return_value" [attr-defined]
- lib/tests/streamlit/config_test.py:733:9: error: "_patch[Union[MagicMock, AsyncMock]]" has no attribute "side_effect" [attr-defined]
+ lib/tests/streamlit/config_test.py:733:9: error: "_patch_default_new" has no attribute "side_effect" [attr-defined]
- lib/tests/streamlit/config_test.py:757:9: error: "_patch[Union[MagicMock, AsyncMock]]" has no attribute "return_value" [attr-defined]
+ lib/tests/streamlit/config_test.py:757:9: error: "_patch_default_new" has no attribute "return_value" [attr-defined]
- lib/tests/streamlit/config_test.py:759:9: error: "_patch[Union[MagicMock, AsyncMock]]" has no attribute "side_effect" [attr-defined]
+ lib/tests/streamlit/config_test.py:759:9: error: "_patch_default_new" has no attribute "side_effect" [attr-defined]
- lib/tests/streamlit/config_test.py:793:9: error: "_patch[Union[MagicMock, AsyncMock]]" has no attribute "return_value" [attr-defined]
+ lib/tests/streamlit/config_test.py:793:9: error: "_patch_default_new" has no attribute "return_value" [attr-defined]
- lib/tests/streamlit/config_test.py:795:9: error: "_patch[Union[MagicMock, AsyncMock]]" has no attribute "side_effect" [attr-defined]
+ lib/tests/streamlit/config_test.py:795:9: error: "_patch_default_new" has no attribute "side_effect" [attr-defined]
|
Thank you! |
class _patch_default_new(_patch[_Mock]): | ||
@overload | ||
def __call__(self, func: _TT) -> _TT: ... | ||
# Can't use the following as ParamSpec is only allowed as last parameter: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Can't use the following as ParamSpec is only allowed as last parameter: | |
# Can't use the following as ParamSpec is only allowed as the last parameter to Concatenate[]: |
assert_type(f_default_new(1), str) | ||
f_default_new("a") # Not an error due to ParamSpec limitations | ||
assert_type(f_explicit_new(1), str) | ||
f_explicit_new("a") # type: ignore[arg-type] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: we currently don't use mypy error codes for type: ignore
s in the test_cases
directory: (see rationale in #8083)
f_explicit_new("a") # type: ignore[arg-type] | |
f_explicit_new("a") # type: ignore |
Closes: #10457