Skip to content

How to raise Error on LiteralString #1434

Answered by erictraut
randolf-scholz asked this question in Q&A
Discussion options

You must be logged in to vote

No, that's not possible (nor would it make sense given the way that subtyping and overloads work in Python). LiteralString is a subtype of str, so if you provide an overload that accepts a str, it will (by definition) accept a LiteralString. A type checker will emit an error only if the supplied arguments fail to match any of the overloaded signatures.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@randolf-scholz
Comment options

@Akuli
Comment options

Answer selected by randolf-scholz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants