How to raise Error on LiteralString #1434
Answered
by
erictraut
randolf-scholz
asked this question in
Q&A
|
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. |
Answered by
erictraut
Jul 21, 2023
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). |
2 replies
Answer selected by
randolf-scholz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No, that's not possible (nor would it make sense given the way that subtyping and overloads work in Python).
LiteralStringis 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.