fix: use is None instead of == None in test files (PEP 8 E711)#19393
fix: use is None instead of == None in test files (PEP 8 E711)#19393harshadkhetpal wants to merge 3 commits intoapache:mainfrom
is None instead of == None in test files (PEP 8 E711)#19393Conversation
There was a problem hiding this comment.
Code Review
This pull request updates Python identity comparisons from == None to is None across several test files to align with PEP 8. While most changes are standard, the update in tests/python/tirx-base/test_tir_base.py breaks tests specifically designed to verify the behavior of overloaded equality operators for TIR expressions. Using is None bypasses these operators, preventing the expected ValueError from being raised and causing the tests to fail.
| assert a is not None | ||
| with pytest.raises(ValueError): | ||
| assert not a == None | ||
| assert not a is None | ||
| b = tirx.StringImm("abc") | ||
| assert b != None | ||
| assert not b == None | ||
| assert b is not None | ||
| assert not b is None |
There was a problem hiding this comment.
This change breaks the test logic in test_eq_ops. This test is specifically designed to verify the behavior of overloaded equality operators (== and !=) for TIR expressions.
For tirx.IntImm, the operators are overloaded to return IR nodes (expressions), and the test verifies that using these expressions in a boolean context (like an assert or not statement) raises a ValueError. By switching to is None and is not None, you are using Python's identity comparison, which bypasses the overloaded operators entirely. Consequently, no ValueError will be raised, and the test will fail to catch the intended behavior (specifically, pytest.raises will fail because no exception occurs).
Since these files have ruff: noqa: E711 at the top, it indicates that the use of == None is intentional for testing purposes. These specific lines should be reverted.
| assert a is not None | |
| with pytest.raises(ValueError): | |
| assert not a == None | |
| assert not a is None | |
| b = tirx.StringImm("abc") | |
| assert b != None | |
| assert not b == None | |
| assert b is not None | |
| assert not b is None | |
| assert a != None | |
| with pytest.raises(ValueError): | |
| assert not a == None | |
| b = tirx.StringImm("abc") | |
| assert b != None | |
| assert not b == None |
Summary
Replace
== Noneand!= Nonecomparisons withis Noneandis not Nonein test files, per PEP 8 (E711).Python's
isoperator is the recommended way to compare with singletons likeNone, as it checks identity rather than equality. Using==can produce unexpected results if__eq__is overridden.Files changed:
tests/python/ir/test_ir_type.py(1 fix)tests/python/tirx-base/test_tir_base.py(4 fixes)tests/python/tirx-base/test_tir_constructor.py(1 fix)Change:
Testing
No behavior change — this is a style/correctness fix per PEP 8 E711. All assertions remain functionally equivalent for
Nonecomparisons.