Skip to content

[Test][Relax] Make the purity assertion in test_call_packed able to fail - #21063

Open
VenishPaneliya wants to merge 1 commit into
apache:mainfrom
VenishPaneliya:test-relax-purity-assert
Open

VenishPaneliya wants to merge 1 commit into
apache:mainfrom
VenishPaneliya:test-relax-purity-assert

Conversation

@VenishPaneliya

Copy link
Copy Markdown
Contributor

In test_call_packed:

    # the function has an annotated return type
    assert "ret_ty=AnyType()" in f_str
    # the purity attribute is set to false
    assert "is_pure=False"

The second assertion tests a non-empty string literal, so it always passes and the check its comment describes never runs. The dump could stop emitting the purity attribute, or emit is_pure=True, and the test would stay green. The in f_str was dropped; the line directly above shows the intended form.

The expected text is right: the function under test is declared @R.function(pure=False), ast_printer.py emits is_pure through build_ast_node as f"{field}={value}", relax.Function declares is_pure: bool, and two assertions in this same file already depend on that rendering — line 223 (assert "is_pure=" in func_str) and line 348 (== "FuncType(params=[],ret=AnyType(),purity=True)").

This is the only PLW0129 ("asserting on a non-empty string literal will always pass") in the repository.

I could not run the test here — it needs a built TVM — so please take the expected-string part on the evidence above rather than on my word; if the dump renders the value differently the assertion will say so immediately in CI. What I did verify is the defect itself: a static check that no assertion in test_call_packed is a bare string literal and that the purity assertion now tests membership (2 failures before this change, 0 after), plus a reduced copy showing that the current form passes even when the dump says is_pure=True while the fixed form fails.

`assert "is_pure=False"` tests a non-empty string literal, so it always
passes and the check its comment describes never runs: the dump could
stop emitting the purity attribute, or emit `is_pure=True`, and the test
would stay green. The line above it is `assert "ret_ty=AnyType()" in
f_str`, so the `in f_str` was dropped.

This branch has not been deployed

No deployments
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