Skip to content

Create case-insensitive Literal type hint #285

Answered by leycec
tvdboom asked this question in Q&A
Discussion options

You must be logged in to vote

Fascinating... and exceedingly clever, too. That's just what we've all come to expect from @tvdboom.

Surprisingly, this now is beginning to seem like more of a mypy issue rather than a @beartype issue. I blame them! Mypy is bad and should feel bad.

Specifically, mypy fails to extend the same semantics applied to standard typing classes to subclasses of those standard typing classes. If mypy accepts a function annotated by typing.Literal[A, B] for any valid literals A and B, then mypy should also accept the same function annotated by YourLiteral[A, B] for any subclass class YourLiteral(typing.Literal):.

But... it doesn't. So, that's a mypy bug. Right? I think? I hope? Please let this not be

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@tvdboom
Comment options

@leycec
Comment options

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