Open
Description
class X:
def __str__(self, arg: int | None = None) -> str:
return f"{arg}"
def user(x: X) -> str:
return x.__str__(arg=42)
main.py:2: note: "__str__" of "X" defined here
main.py:6: error: Unexpected keyword argument "arg" for "__str__" of "X" [call-arg]
https://mypy-play.net/?mypy=latest&python=3.10&gist=b0426a5fffb000335d04492959d69b34
This works fine at runtime. Interestingly, mypy allows passing additional positional arguments to __str__
, e.g. x.__str__(42)
. I assume something is overzealously applying the general rule that dunders usually don't accept keyword arguments.
Metadata
Metadata
Assignees
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity