Skip to content

Noob question: Type check for HyExpression? #2152

Answered by Kodiologist
nicoszerman asked this question in Q&A
Discussion options

You must be logged in to vote

hy.models.Expression (formerly HyExpression) is only one of several types that Hy uses for its code. The supertype that everything else inherits from is hy.models.Object. Note however that checking (isinstance code hy.models.Object) won't catch objects that could be promoted to models, such as 5, which would be promoted to hy.models.Integer in e.g. (hy.eval 5). The most general approach is to call hy.as-model and check if it raises an error.

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@nicoszerman
Comment options

@Kodiologist
Comment options

@nicoszerman
Comment options

@Kodiologist
Comment options

Answer selected by allison-casey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants