I noticed today that I’m not able to declare: sign: Literal[-1, +1], because +1 counts as an “arbitrary expression”. I was a bit surprised about this, especially given that in Python +1 is as much an expression as -1. I observed the same behaviour in mypy and pyright.
Is there any reason why this happens? I think it would make sense to change this behaviour. I know that I could use Literal[-1, 1], but in some contexts using an explicit sign is more consistent with the domain.
This is explicitly specified in PEP 586 – Literal Types | peps.python.org the only legal operator inside Literal[] is unary minus on ints. But as you say, it seems fine to allow unary + too; it’s trivial to implement and can improve clarity in some cases.