Skip to content

Add mechanism to evaluate generic aliases in boolean contexts#30

Closed
dnwpark wants to merge 3 commits intomainfrom
special-form
Closed

Add mechanism to evaluate generic aliases in boolean contexts#30
dnwpark wants to merge 3 commits intomainfrom
special-form

Conversation

@dnwpark
Copy link
Contributor

@dnwpark dnwpark commented Jan 12, 2026

Generic aliases cannot be properly evaluated in boolean contexts. For example, given:

type IsNotInt[T] = not Is[T, int]
type SetOfNotInt[T] = set[T] if IsNotInt[T] else T

then:

    t = eval_typing(SetOfNotInt[int])
    assert t is int

fails with assert set[int] is int

This is because IsNotInt[T] is evaluated as a boolean directly resulting in True.

This PR adds @bool_special_form which can be used on classes:

class IsNotInt[T]:
    __expr__ = not Is[T, int]

allowing the assertion to succeed.

@dnwpark dnwpark requested a review from msullivan January 12, 2026 23:51
@dnwpark dnwpark closed this Jan 13, 2026
@dnwpark dnwpark deleted the special-form branch January 28, 2026 01:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant