We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
To Reproduce
from typing import Literal def fun(**kwargs) -> None: ... class A: def __init__(self): self.a: Literal["a"] = "a" def test(self) -> None: return fun(**{self.a: "a"}) # error: Keywords must be strings [misc]
Your Environment
Also happens for dataclasses:
from dataclasses import dataclass from typing import Literal, Mapping @dataclass class Foo: a: int b: int x: Mapping[Literal["a", "b"], int] = {"a":1, "b": 2} y: Foo = Foo(**x) # error: Keywords must be strings [misc]
https://mypy-play.net/?mypy=latest&python=3.11&gist=3450797f9c8ca85bb6b04240c8dadb88
This seems to be the relevant code:
mypy/mypyc/lib-rt/getargs.c
Lines 390 to 396 in b901d21
at other places _PyDict_GetItemStringWithError is used which wraps keyword argument in PyUnicode_FromString
_PyDict_GetItemStringWithError
PyUnicode_FromString
mypy/mypyc/lib-rt/pythonsupport.h
Lines 358 to 369 in b901d21
That is not the relevant code, as it is mypyc runtime code. This issue is about mypy, not mypyc. The error appears to be raised here:
mypy/messages.py: self.fail("Keywords must be strings", context)
I haven't looked further.
Activity
randolf-scholz commentedon Jul 26, 2023
Also happens for dataclasses:
https://mypy-play.net/?mypy=latest&python=3.11&gist=3450797f9c8ca85bb6b04240c8dadb88
randolf-scholz commentedon Jul 26, 2023
This seems to be the relevant code:
mypy/mypyc/lib-rt/getargs.c
Lines 390 to 396 in b901d21
at other places
_PyDict_GetItemStringWithError
is used which wraps keyword argument inPyUnicode_FromString
mypy/mypyc/lib-rt/pythonsupport.h
Lines 358 to 369 in b901d21
JelleZijlstra commentedon Jul 26, 2023
That is not the relevant code, as it is mypyc runtime code. This issue is about mypy, not mypyc. The error appears to be raised here:
I haven't looked further.