mypy runs perfectly on terminal, but when running on pre-commit stage, I am getting the error Unexpected keyword argument for every property in my class
from attrs import define, field
@define(
frozen=True,
kw_only=True,
slots=True,
auto_detect=True,
order=False,
auto_attribs=True,
)
class MyClass:
a: str = field(default="")
b: str = field(default="")
def myMethod(self) -> Any:
return MyClass(a=self.a, b="b_value")
mypy pre-commit failed:
error: Unexpected keyword argument "a" for MyClass (line: return MyClass...)
error: Unexpected keyword argument "b" for MyClass (line: return MyClass...)
.pre-commit-config.yaml:
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
hooks:
- id: mypy
args: ["--config-file", "mypy.ini"]
alternatively, as the README states:
Because pre-commit runs mypy from an isolated virtualenv (without your dependencies) you may also find it useful to add the typed dependencies to additional_dependencies so mypy can better perform dynamic analysis
ala:
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
hooks:
- id: mypy
additional_dependencies: [attrs]
# also you don't need this, mypy checks mypy.ini by default
# args: ["--config-file", "mypy.ini"]
disclaimer: I wrote pre-commit