Skip to content

sinitax/bearcheck

Repository files navigation

bearcheck

Tiny extension to beartype, which allows inline type assertion and narrowing similar to check_type from typeguard.

Using bearcheck() is faster and safer than check_type(), since it leverages the incredibly fast beartype library for type checking, and allows specifying the exact return type.

Usage

from bearcheck import bearcheck, Check

var = bearcheck("a", Check[Literal["a", "b"]])
reveal_type(var)  # Type of "var" is "Literal['a', 'b']"

.. as opposed to ..

from typeguard import check_type

var = check_type("a", Literal["a", "b"])
reveal_type(var)  # Type of "var" is "Any"

type_check() returns Any if the type hint is not primitive.

About

Tiny beartype helper lib for inline type assertion and narrowing (not affiliated)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors