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

Arguments to protocol methods should never be positional-or-keyword #441

Open
JelleZijlstra opened this issue Nov 5, 2023 · 1 comment · May be fixed by #442
Open

Arguments to protocol methods should never be positional-or-keyword #441

JelleZijlstra opened this issue Nov 5, 2023 · 1 comment · May be fixed by #442

Comments

@JelleZijlstra
Copy link
Collaborator

It's easy to write a protocol like this:

class P(Protocol):
    def write(self, arg: bytes) -> None: ...

But it's almost never what you want. Typically you'd use a protocol like this for a function that takes an argument p of type P. That function probably does p.write(some_buffer) or possibly p.write(arg=some_buffer), but almost certainly not both. So the protocol should either have a positional-only or a keyword-only arg, but a positional-or-keyword arg is probably a mistake.

I think it would be reasonable for flake8-pyi to warn about this.

@Avasam
Copy link
Contributor

Avasam commented Nov 22, 2023

Agreed. I have likely written many protocols like this without further though.

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

Successfully merging a pull request may close this issue.

2 participants