-
|
I want to have beartype print out the proper type annotation for a variable because I can't seem to do it right myself. Example: from beartype.typing import Callable
from pygments.lexers import PythonLexer
from pygments.lexer import RegexLexer
from pygments.token import _TokenType
lexer: RegexLexer = PythonLexer()
root_tokens: list[str] | list[tuple[str, _TokenType | Callable, str]] = (
lexer.tokens["root"]
)
print(root_tokens)Now try using beartype_this_package with that. I could just use type |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
|
Type inference. Yes. So much yes! Full-blown type inference support in @beartype would be delightful. Someone make a @beartype-based runtime equivalent of the
I dimly recall @wesselb the Wise needing something similar for Plum, maybe? Does Plum do any sort of runtime type inference? Probably not, huh? Yeah. That was always gonna be a longshot. But if Plum does do some sort of runtime type inference, perhaps we could upstream that into @beartype itself as a new public API... which @leycec then has to laboriously maintain for the rest of his life. Gah! What am I doing!? This sounds suspiciously like maintenance prison. Ahem... What I meant is that this is a fascinating and incredibly relevant discussion. Thanks so much for igniting this lit bonfire, @Moosems. 🔥 |
Beta Was this translation helpful? Give feedback.
-
|
Tell @Moosems what he's won, GitHub Bear! It's... our newest feature request. Also, I implemented this tonight. 🤣 |
Beta Was this translation helpful? Give feedback.
Type inference. Yes. So much yes! Full-blown type inference support in @beartype would be delightful. Someone make a @beartype-based runtime equivalent of the
mypy-specificreveal_type()fake function happen. I revel in this idea.reveal_type()tends to be rather useless in practice.mypyis just a static type-checker.mypydoesn't actually run at runtime and thus generally no idea what it's talking about. The set of all type hints that static type-checkers likemypyandpyrightcan correctly infer is a lot smaller than the set of all type hints that runtime type-checkers like @beartype andtypeguardcan correctly infer – in theory, anyway.I dimly recall @wesselb the Wise needing somethi…