Replies: 1 comment 2 replies
-
The expression The rest of the code looks fine and is an appropriate use of PEP 747. To cover all possible cases, your implementation of |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Sometimes I need to iterate over
Literal
values and for such cases I tend to useget_args
, which revealed type istuple[Any, ...]
.In those moment I wished I had type safe
Literal
value extraction possible, but it wasn't: boundingTypeVar
withLiteral
isn't allowed as well wrappingtype
around such «generic literal».So, when PEP 747 became provisionally supported in Pyright I started playing around with it and realized it's actually possible to achieve what I want for
Literal
types: it's hacky but still.See the code in Pyright playground or the code snippet provided below.
Note that ellipsis inside
Literal
is crucial, nothing works without it.Is this Pyright «bug»? Should such behavior—very handy I'd say 🙂— be allowed?
Beta Was this translation helpful? Give feedback.
All reactions