Skip to content

[mypy] Missing positional argument "x" in call to "C" #18

@dosisod

Description

@dosisod

I am getting mypy errors when using the inject decorator on classes:

# file.py

from kink import di, inject

di["x"] = 42

@inject
class C:
    def __init__(self, x: int) -> None:
        print(x)


c = C()

Running mypy with:

$ mypy file.py
file.py:13: error: Missing positional argument "x" in call to "C"
Found 1 error in 1 file (checked 1 source file)

Version info:

$ pip freeze
kink==0.6.2
mypy==0.910
mypy-extensions==0.4.3
toml==0.10.2
typing-extensions==3.10.0.2

$ python --version
Python 3.9.7

The only workaround I can see is this:

class C:
    def __init__(self, x: int = di["x"]) -> None:

Which means the inject decorator isn't needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions