Allow self binding for generic ParamSpec#17123
Open
cdce8p wants to merge 1 commit intopython:masterfrom
Open
Conversation
This comment has been minimized.
This comment has been minimized.
Collaborator
Author
|
Primer result analysis: antidoteThey use a custom dependency injection and function overload to remove the first argument with werkzeugThe error comes down to this class A:
import json
json_dumps = staticmethod(json.dumps)
def func(self, j: str) -> None:
self.json_dumps(j)Mypy doesn't recognize that ibisFalse positive which is removed. |
fd4a62a to
83f3482
Compare
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: ibis (https://github.com/ibis-project/ibis)
- ibis/expr/types/relations.py:3251: error: Missing positional argument "predicates" in call to "__call__" of "_Wrapped" [call-arg]
xarray (https://github.com/pydata/xarray)
+ xarray/tests/test_formatting_html.py: note: In member "test_empty_mapping" of class "Test_summarize_datatree_children":
+ xarray/tests/test_formatting_html.py:268: error: Invalid self argument "Test_summarize_datatree_children" to attribute function "func" with type "Callable[[Mapping[str, DataTree[Any]]], None]" [misc]
+ xarray/tests/test_formatting_html.py:268: error: Too many arguments [call-arg]
+ xarray/tests/test_formatting_html.py: note: In member "test_one_child" of class "Test_summarize_datatree_children":
+ xarray/tests/test_formatting_html.py:289: error: Invalid self argument "Test_summarize_datatree_children" to attribute function "func" with type "Callable[[Mapping[str, DataTree[Any]]], None]" [misc]
+ xarray/tests/test_formatting_html.py:289: error: Too many arguments [call-arg]
+ xarray/tests/test_formatting_html.py: note: In member "test_two_children" of class "Test_summarize_datatree_children":
+ xarray/tests/test_formatting_html.py:316: error: Invalid self argument "Test_summarize_datatree_children" to attribute function "func" with type "Callable[[Mapping[str, DataTree[Any]]], None]" [misc]
+ xarray/tests/test_formatting_html.py:316: error: Too many arguments [call-arg]
+ xarray/tests/test_formatting_html.py: note: In member "test_end" of class "Test__wrap_datatree_repr":
+ xarray/tests/test_formatting_html.py:335: error: Invalid self argument "Test__wrap_datatree_repr" to attribute function "func" with type "Callable[[str, bool], None]" [misc]
+ xarray/tests/test_formatting_html.py:335: error: Function gets multiple values for keyword argument "end" [misc]
+ xarray/tests/test_formatting_html.py: note: In member "test_not_end" of class "Test__wrap_datatree_repr":
+ xarray/tests/test_formatting_html.py:367: error: Invalid self argument "Test__wrap_datatree_repr" to attribute function "func" with type "Callable[[str, bool], None]" [misc]
+ xarray/tests/test_formatting_html.py:367: error: Function gets multiple values for keyword argument "end" [misc]
- xarray/tests/test_plot.py:226: error: Missing positional argument "self" in call to "__call__" of "_Wrapped" [call-arg]
- xarray/tests/test_plot.py:229: error: Missing positional argument "self" in call to "__call__" of "_Wrapped" [call-arg]
- xarray/tests/test_plot.py:232: error: Missing positional argument "self" in call to "__call__" of "_Wrapped" [call-arg]
+ xarray/tests/test_plot.py:226: error: Invalid self argument "DataArrayPlotAccessor" to attribute function "__call__" with type "Callable[[DataArray, DefaultNamedArg(Hashable | None, 'row'), DefaultNamedArg(Hashable | None, 'col'), DefaultNamedArg(int | None, 'col_wrap'), DefaultNamedArg(Any | None, 'ax'), DefaultNamedArg(Hashable | None, 'hue'), DefaultNamedArg(dict[str, Any] | None, 'subplot_kws'), KwArg(Any)], None]" [misc]
+ xarray/tests/test_plot.py:229: error: Invalid self argument "DataArrayPlotAccessor" to attribute function "__call__" with type "Callable[[DataArray, DefaultNamedArg(Hashable | None, 'row'), DefaultNamedArg(Hashable | None, 'col'), DefaultNamedArg(int | None, 'col_wrap'), DefaultNamedArg(Any | None, 'ax'), DefaultNamedArg(Hashable | None, 'hue'), DefaultNamedArg(dict[str, Any] | None, 'subplot_kws'), KwArg(Any)], None]" [misc]
+ xarray/tests/test_plot.py:232: error: Invalid self argument "DataArrayPlotAccessor" to attribute function "__call__" with type "Callable[[DataArray, DefaultNamedArg(Hashable | None, 'row'), DefaultNamedArg(Hashable | None, 'col'), DefaultNamedArg(int | None, 'col_wrap'), DefaultNamedArg(Any | None, 'ax'), DefaultNamedArg(Hashable | None, 'hue'), DefaultNamedArg(dict[str, Any] | None, 'subplot_kws'), KwArg(Any)], None]" [misc]
- xarray/tests/test_plot.py:235: error: Missing positional argument "self" in call to "__call__" of "_Wrapped" [call-arg]
+ xarray/tests/test_plot.py:235: error: Invalid self argument "DataArrayPlotAccessor" to attribute function "__call__" with type "Callable[[DataArray, DefaultNamedArg(Hashable | None, 'row'), DefaultNamedArg(Hashable | None, 'col'), DefaultNamedArg(int | None, 'col_wrap'), DefaultNamedArg(Any | None, 'ax'), DefaultNamedArg(Hashable | None, 'hue'), DefaultNamedArg(dict[str, Any] | None, 'subplot_kws'), KwArg(Any)], None]" [misc]
- xarray/tests/test_plot.py:245: error: Missing positional argument "self" in call to "__call__" of "_Wrapped" [call-arg]
- xarray/tests/test_plot.py:248: error: Missing positional argument "self" in call to "__call__" of "_Wrapped" [call-arg]
- xarray/tests/test_plot.py:252: error: Missing positional argument "self" in call to "__call__" of "_Wrapped" [call-arg]
- xarray/tests/test_plot.py:255: error: Missing positional argument "self" in call to "__call__" of "_Wrapped" [call-arg]
+ xarray/tests/test_plot.py:245: error: Invalid self argument "DataArrayPlotAccessor" to attribute function "__call__" with type "Callable[[DataArray, DefaultNamedArg(Hashable | None, 'row'), DefaultNamedArg(Hashable | None, 'col'), DefaultNamedArg(int | None, 'col_wrap'), DefaultNamedArg(Any | None, 'ax'), DefaultNamedArg(Hashable | None, 'hue'), DefaultNamedArg(dict[str, Any] | None, 'subplot_kws'), KwArg(Any)], None]" [misc]
+ xarray/tests/test_plot.py:248: error: Invalid self argument "DataArrayPlotAccessor" to attribute function "__call__" with type "Callable[[DataArray, DefaultNamedArg(Hashable | None, 'row'), DefaultNamedArg(Hashable | None, 'col'), DefaultNamedArg(int | None, 'col_wrap'), DefaultNamedArg(Any | None, 'ax'), DefaultNamedArg(Hashable | None, 'hue'), DefaultNamedArg(dict[str, Any] | None, 'subplot_kws'), KwArg(Any)], None]" [misc]
+ xarray/tests/test_plot.py:252: error: Invalid self argument "DataArrayPlotAccessor" to attribute function "__call__" with type "Callable[[DataArray, DefaultNamedArg(Hashable | None, 'row'), DefaultNamedArg(Hashable | None, 'col'), DefaultNamedArg(int | None, 'col_wrap'), DefaultNamedArg(Any | None, 'ax'), DefaultNamedArg(Hashable | None, 'hue'), DefaultNamedArg(dict[str, Any] | None, 'subplot_kws'), KwArg(Any)], None]" [misc]
+ xarray/tests/test_plot.py:255: error: Invalid self argument "DataArrayPlotAccessor" to attribute function "__call__" with type "Callable[[DataArray, DefaultNamedArg(Hashable | None, 'row'), DefaultNamedArg(Hashable | None, 'col'), DefaultNamedArg(int | None, 'col_wrap'), DefaultNamedArg(Any | None, 'ax'), DefaultNamedArg(Hashable | None, 'hue'), DefaultNamedArg(dict[str, Any] | None, 'subplot_kws'), KwArg(Any)], None]" [misc]
- xarray/tests/test_plot.py:266: error: Missing positional argument "self" in call to "__call__" of "_Wrapped" [call-arg]
- xarray/tests/test_plot.py:270: error: Missing positional argument "self" in call to "__call__" of "_Wrapped" [call-arg]
+ xarray/tests/test_plot.py:266: error: Invalid self argument "DataArrayPlotAccessor" to attribute function "__call__" with type "Callable[[DataArray, DefaultNamedArg(Hashable | None, 'row'), DefaultNamedArg(Hashable | None, 'col'), DefaultNamedArg(int | None, 'col_wrap'), DefaultNamedArg(Any | None, 'ax'), DefaultNamedArg(Hashable | None, 'hue'), DefaultNamedArg(dict[str, Any] | None, 'subplot_kws'), KwArg(Any)], None]" [misc]
+ xarray/tests/test_plot.py:270: error: Invalid self argument "DataArrayPlotAccessor" to attribute function "__call__" with type "Callable[[DataArray, DefaultNamedArg(Hashable | None, 'row'), DefaultNamedArg(Hashable | None, 'col'), DefaultNamedArg(int | None, 'col_wrap'), DefaultNamedArg(Any | None, 'ax'), DefaultNamedArg(Hashable | None, 'hue'), DefaultNamedArg(dict[str, Any] | None, 'subplot_kws'), KwArg(Any)], None]" [misc]
- xarray/tests/test_plot.py:304: error: Missing positional argument "self" in call to "__call__" of "_Wrapped" [call-arg]
- xarray/tests/test_plot.py:307: error: Missing positional argument "self" in call to "__call__" of "_Wrapped" [call-arg]
+ xarray/tests/test_plot.py:304: error: Invalid self argument "DataArrayPlotAccessor" to attribute function "__call__" with type "Callable[[DataArray, DefaultNamedArg(Hashable | None, 'row'), DefaultNamedArg(Hashable | None, 'col'), DefaultNamedArg(int | None, 'col_wrap'), DefaultNamedArg(Any | None, 'ax'), DefaultNamedArg(Hashable | None, 'hue'), DefaultNamedArg(dict[str, Any] | None, 'subplot_kws'), KwArg(Any)], None]" [misc]
+ xarray/tests/test_plot.py:307: error: Invalid self argument "DataArrayPlotAccessor" to attribute function "__call__" with type "Callable[[DataArray, DefaultNamedArg(Hashable | None, 'row'), DefaultNamedArg(Hashable | None, 'col'), DefaultNamedArg(int | None, 'col_wrap'), DefaultNamedArg(Any | None, 'ax'), DefaultNamedArg(Hashable | None, 'hue'), DefaultNamedArg(dict[str, Any] | None, 'subplot_kws'), KwArg(Any)], None]" [misc]
- xarray/tests/test_plot.py:317: error: Missing positional argument "self" in call to "__call__" of "_Wrapped" [call-arg]
+ xarray/tests/test_plot.py:317: error: Invalid self argument "DataArrayPlotAccessor" to attribute function "__call__" with type "Callable[[DataArray, DefaultNamedArg(Hashable | None, 'row'), DefaultNamedArg(Hashable | None, 'col'), DefaultNamedArg(int | None, 'col_wrap'), DefaultNamedArg(Any | None, 'ax'), DefaultNamedArg(Hashable | None, 'hue'), DefaultNamedArg(dict[str, Any] | None, 'subplot_kws'), KwArg(Any)], None]" [misc]
- xarray/tests/test_plot.py:389: error: Missing positional argument "self" in call to "__call__" of "_Wrapped" [call-arg]
+ xarray/tests/test_plot.py:389: error: Invalid self argument "DataArrayPlotAccessor" to attribute function "__call__" with type "Callable[[DataArray, DefaultNamedArg(Hashable | None, 'row'), DefaultNamedArg(Hashable | None, 'col'), DefaultNamedArg(int | None, 'col_wrap'), DefaultNamedArg(Any | None, 'ax'), DefaultNamedArg(Hashable | None, 'hue'), DefaultNamedArg(dict[str, Any] | None, 'subplot_kws'), KwArg(Any)], None]" [misc]
- xarray/tests/test_plot.py:519: error: Missing positional argument "self" in call to "__call__" of "_Wrapped" [call-arg]
... (truncated 117 lines) ...
antidote (https://github.com/Finistere/antidote)
+ tests/test_examples.py:37: error: Invalid self argument "Files" to attribute function "read" with type "Callable[[str], None]" [misc]
+ tests/test_examples.py:37: error: Too many arguments [call-arg]
+ tests/test_examples.py:41: error: Invalid self argument "Files" to attribute function "read" with type "Callable[[str], None]" [misc]
+ tests/test_examples.py:41: error: Too many arguments [call-arg]
+ tests/core/test_inject.py:517: error: Attribute function "method" with type "Callable[[], None]" does not accept self argument [misc]
+ tests/core/test_inject.py:519: error: Invalid self argument "Conf" to attribute function "get" with type "Callable[[str], None]" [misc]
+ tests/core/test_inject.py:519: error: Too many arguments [call-arg]
+ tests/core/test_inject.py:522: error: Attribute function "method" with type "Callable[[], None]" does not accept self argument [misc]
+ tests/core/test_inject.py:523: error: Invalid self argument "Conf" to attribute function "get" with type "Callable[[str], None]" [misc]
+ tests/core/test_inject.py:523: error: Unexpected keyword argument "key" [call-arg]
werkzeug (https://github.com/pallets/werkzeug)
+ src/werkzeug/test.py:370: error: Too many positional arguments [misc]
+ src/werkzeug/test.py:370: error: Argument 1 has incompatible type "Mapping[str, Any]"; expected "bool" [arg-type]
|
|
Great work! Do you think we can get any reviews on this one? |
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.
Required for python/typeshed#11662
Discussion: https://discuss.python.org/t/allow-self-binding-for-generic-paramspec/50948