You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As Python doesn't allow an isinstance check of a TypeAlias there are checks in the code for the sub-components of the TypeAlias. Unfortunately these are not all consistent which could result in unexpected behavior. The beartype package has a is_bearable function that could be used for this purpose as shown here:
fromtypingimportTypeAliasfromcollections.abcimportSequencefrombuild123dimportVectorfrombeartype.doorimportis_bearableVectorLike: TypeAlias=Vector|Sequence[float|int]
forvin [Vector(1, 2, 3), "Vector", (1, 2, 3)]:
ifis_bearable(v, VectorLike):
print(f"{v} is a VectorLike")
else:
print(f"{v} is not a VectorLike")
Vector(1, 2, 3) is a VectorLike
Vector is not a VectorLike
(1, 2, 3) is a VectorLike
To enable portability it might be a good idea to wrap is_bearable into a build123d is_type_alias (or similar) function.
The text was updated successfully, but these errors were encountered:
As Python doesn't allow an isinstance check of a TypeAlias there are checks in the code for the sub-components of the TypeAlias. Unfortunately these are not all consistent which could result in unexpected behavior. The
beartype
package has ais_bearable
function that could be used for this purpose as shown here:To enable portability it might be a good idea to wrap
is_bearable
into a build123dis_type_alias
(or similar) function.The text was updated successfully, but these errors were encountered: