fix: use is None instead of == None in test files (PEP 8 E711)#19393
Open
harshadkhetpal wants to merge 3 commits intoapache:mainfrom
Open
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)#19393harshadkhetpal wants to merge 3 commits intoapache:mainfrom
Conversation
Contributor
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.
Contributor
|
@tvm-bot rerun |
Contributor
|
Failed to re-run CI in https://github.com/apache/tvm/actions/runs/24400711155 Detailswith response |
861510a to
29db40f
Compare
29db40f to
9bfd176
Compare
The `== None` / `!= None` comparisons in `test_eq_ops` are intentional: the test exercises the overloaded `__eq__` / `__ne__` operators on `IntImm` / `StringImm`, which raise `ValueError` when coerced to bool. Rewriting them as `is None` / `is not None` bypasses the overloads and breaks the test, so add a NOTE comment flagging the constraint.
9bfd176 to
369178c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.