Is an equivalent of `typeguard.check_type` available?
See original GitHub issueI’d like to use Beartype’s custom PEP-compliant validators, but my use case requires that I make an explicit call to a function similar to typeguard.check_type()
. It doesn’t seem like beartype is currently designed to expose a method like this; the decorators are all I can find. How hard would it be to expose a method like this? If I’m given some general guidance I’m happy to attempt a PR for it myself.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Documentation - Advanced Types - TypeScript
A type guard is some expression that performs a runtime check that guarantees the type in some scope. Using type predicates. To define...
Read more >User guide — Typeguard 2.13.3 documentation - Read the Docs
The simplest way to type checking of both argument values and the return value for a single function is to use the @typechecked...
Read more >How to get the types you want with TypeScript type guards
TypeScript comes with some built-in type guards: typeof and instanceof . They're very useful, but have limited scope. For example, typeof can ...
Read more >Typescript check object by type or interface at runtime with ...
And i was thinking, can this be done with user defined typeguard in a generic way for any type of object with multiple...
Read more >How to use type guards in TypeScript - LogRocket Blog
A type guard is a TypeScript technique used to get information about the type of a variable, usually within a conditional block.
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
That’s intentional. To allow for fast constant-time type checking,
beartype
doesn’t exhaustively check the entirety of lists and other collections. Instead each time it’s called, it randomly picks a position and checks it. Most of the time, you don’t tend to have lists like your example with only a few bad items, it’s usually entirely the wrong type so this will catch it immediately. If there are incorrect values, repeatedly calling will eventually produce a typecheck failure.However this might not be a desirable behaviour for an explicit type-checking function, so it’d probably be better to default to the
O(n)
mode described here, once implemented: #60You are not wrong. You never are. You know this already, which is why I’m generalizing the signature of our currently implemented and thoroughly untested
is_bearable()
tester to read:For orthogonality and (more importantly) 'cause this is @beartype,
conf
will probably default toBeartypeConf()
which defaults to our defaultBeartypeStrategy.O1
strategy. Gotta type-check in constant time if you’re gonna keep up with the big boys!Now, let’s see if I actually do something and manage to test any of this. The sweat pouring off my chin is real.