Skip to content
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

Allow self binding for generic ParamSpec #17123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cdce8p
Copy link
Collaborator

@cdce8p cdce8p commented Apr 14, 2024

Copy link
Contributor

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

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]

ibis (https://github.com/ibis-project/ibis)
- ibis/expr/types/relations.py:3064: error: Missing positional argument "predicates" in call to "__call__" of "_Wrapped"  [call-arg]

@cdce8p
Copy link
Collaborator Author

cdce8p commented Apr 14, 2024

Primer result analysis:

antidote

They use a custom dependency injection and function overload to remove the first argument with Concatenate.
https://github.com/Finistere/antidote/blob/v2.0.0/src/antidote/core/__init__.py#L1201-L1204
While also freely mixing calling the function with self or the class name.
https://github.com/Finistere/antidote/blob/v2.0.0/tests/test_examples.py#L36-L44

werkzeug

The 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 json_dumps is a @staticmethod. A workaround would be to move to the module scope and remove the staticmethod wrapper.

ibis

False positive which is removed.

@cdce8p cdce8p added the topic-paramspec PEP 612, ParamSpec, Concatenate label Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-paramspec PEP 612, ParamSpec, Concatenate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant