Replies: 2 comments
-
This is related to a recent discussion on the typing forum. That discussion involved a bunch of (unrelated) issues, but it raised the same question you're raising above. The question is whether bidirectional type inference for the expression I need to give this some additional thought, but I'm not convinced that pyright's behavior is correct in this case. |
Beta Was this translation helpful? Give feedback.
-
Iiiiinteresting. Thanks! I'll follow the discussion with interest. |
Beta Was this translation helpful? Give feedback.
-
In this example code, no error is produced on line 3, but on line 5 the type of
x
is given asdict[int, int]
. On line 7 this is underscored when you finally get an error:See: https://pyright-play.net/?pythonVersion=3.14&strict=true&code=GYJw9gtgBALgngBwJYDsDmUkQWEMoCyAhgsugFDkAeAXISWWgNqowA0mK%2BAPlAM4wQAXSgBeKAG8AjHQBMAX0ogApgDdlRADYB9eAmUAKKgEpKVJgGYR4gETAwAVxA2gA
It seems to me that either:
: Mapping[...]
type hint on line 3 should work, and the type ofx
should beMapping[int, int | str]
and no assignments should be allowed orBeta Was this translation helpful? Give feedback.
All reactions