Annotate `is_bearable` to return TypeGuard
See original GitHub issueLooks like TypeGuard
is suitable as a return type for is_bearable
for it to support mypy. I haven’t tested. Maybe it does support mypy already?
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:11 (7 by maintainers)
Top Results From Across the Web
Is it impossible to have a function return a user-defined type ...
Therefore, my suggestion would be to change your createFilter() so that the actual type guard function has a return type annotation:
Read more >Narrowing types with TypeGuard in Python - Redowan Delowar
When TypeGuard is used to annotate the return type of a function or method that accepts at least one parameter, that function or...
Read more >User guide — Typeguard 2.13.3 documentation - Read the Docs
If the function is called with incompatible types, or check_return_type() is used and the return value does not match the return type annotation, ......
Read more >Type guard annotations don't work in jsdoc #25127 - GitHub
Actual behavior: No narrowing, and Entry.isInit 's return type is just boolean.
Read more >PEP 647 – User-Defined Type Guards
TypeGuard is a special form that accepts a single type argument. It is used to annotate the return type of a user-defined type...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Resolved by db2b98e. Thanks so much for the gentle reminder. I’d gradually forgotten about PEP 647 and
typing.TypeGuard
, because it’s only supported only Python ≥ 3.10. But have no fear! Python can do anything that it probably shouldn’t, so we forcibly made this work by transparently falling back tobool
under Python < 3.10. Dynamically interpreted languages for the win.Unrelatedly, it turns out our ANSI stripping routine was indeed busted. I’m unclear why exactly that blew up tonight – but it did, spectacularly. But have no fear! I forcibly made that work too by removing a single excessive backslash. If you’re curious, here’s the working version (…which now resides in
beartype._util.text.utiltextcolour
, just because):\o/
“Type checkers are special cased to always know what
typing_extensions
is even if it isn’t installed (it’s treated like part of the standard library)[^1]”. The following should work:This should simplify the code considerably I believe 😄 !
[^1]: A quote from a mypy core dev