pyinfra-dev / pyinfra-dev/pyinfra

Positional arguments in any operations result in `Too few arguments` mypy errors

Open
#1,389 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

API bug
Dominant language
Python
Stars
6k
Forks
548
Avg merge
7d 17h
Merged PRs (30d)
13

Description

To Reproduce

Consider the following trivial deploy, using server here, but pretty much any operation would reproduce it:

$ cat test.py
from pyinfra.operations import server
server.shell('echo')
$ uv run --extra dev mypy test.py
test.py:2: error: Too few arguments for "__call__" of "PyinfraOperation"  [call-arg]
test.py:2: error: Argument 1 to "__call__" of "PyinfraOperation" has incompatible type "str"; expected "bool"  [arg-type]

Expected behavior

This should type check without mypy complaining.

Workaround

This is likely caused by this workaround
https://github.com/pyinfra-dev/pyinfra/blob/39d1d31b374c85c69f6fe074b067f3aa7989f2a4/pyinfra/api/arguments_typed.py#L29-L79

It seems like using explicit keyword arguments for the operations works around the issue -- this passes mypy:

from pyinfra.operations import server
server.shell(commands='echo')

Proper fix?

I'm not sure if it's really possible, from reading

, it seems that it's only possible to provide extra positional arguments by using Protocol with __call__ and ParamSpec. So unless one specifies all the extra arguments (i.e. _sudo/_sudo_user/_use_sudo_login/...), it's not really possible to use arguments from P.args (i.e. the actual operation's arguments) as positional arguments.

So I guess I'm not really expecting a fix, but figured it's worth creating an issue so at least other people can find it and the workaround via search.

Meta

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the mypy errors with the test.py example and inspect pyinfra/api/arguments_typed.py around lines 29–79. Review the linked typing references and related pull request #1105 to determine whether positional operation arguments can be represented; done means positional calls such as server.shell('echo') type-check without errors, or the limitation and keyword workaround are documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.