-
current Pyright (1.1.374) does not generate errors for unpacking Iterable to fixed length arguments. simple casefrom collections.abc import Iterable
def f(): pass
def g(x: Iterable[str]): f(*x) common typo casefunction forwarding kwargs, but mistyped from typing import TypedDict, Unpack
class A(TypedDict, total=False):
x: int
def f(**kwargs: Unpack[A]):
pass
def g(**kwargs: Unpack[A]):
f(*kwargs) # common typo: single asterisk
g(x=3) # TypeError: f() takes 0 positional arguments but 1 was given |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This behavior is intended, so I don't consider this a bug. The python typing spec does not specify whether a type checker should generate an error when using an unpack operator on an operand of unknown length. This is a behavior that should arguably be specified one way or another in the spec, but currently it is not. Pyright's current behavior is based on two principles:
For these reasons, I don't plan to modify the behavior here — at least not now. If the typing spec is updated or there is some consensus in the community that this condition should generate a type error, I'm open to changing this behavior. If you'd like to start a discussion about this, I recommend posting to the Python typing forum. |
Beta Was this translation helpful? Give feedback.
This behavior is intended, so I don't consider this a bug. The python typing spec does not specify whether a type checker should generate an error when using an unpack operator on an operand of unknown length. This is a behavior that should arguably be specified one way or another in the spec, but currently it is not. Pyright's current behavior is based on two principles: