How to raise Error on LiteralString #1434
-
This issue come from pandas-stubs. Is it possible, using
i.e. any non-literal string is ok, but for literal string the type checking acts as a defense against typos. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
No, that's not possible (nor would it make sense given the way that subtyping and overloads work in Python). |
Beta Was this translation helpful? Give feedback.
No, that's not possible (nor would it make sense given the way that subtyping and overloads work in Python).
LiteralString
is a subtype ofstr
, so if you provide an overload that accepts astr
, it will (by definition) accept aLiteralString
. A type checker will emit an error only if the supplied arguments fail to match any of the overloaded signatures.