Skip to content

fix(llvm/**.py): fix comparison to None #94018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 28, 2024
Merged

fix(llvm/**.py): fix comparison to None #94018

merged 1 commit into from
Aug 28, 2024

Conversation

e-kwsm
Copy link
Contributor

@e-kwsm e-kwsm commented May 31, 2024

from PEP8 (https://peps.python.org/pep-0008/#programming-recommendations):

Comparisons to singletons like None should always be done with is or is not, never the equality operators.

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented May 31, 2024

@llvm/pr-subscribers-testing-tools

Author: Eisuke Kawashima (e-kwsm)

Changes

from PEP8 (https://peps.python.org/pep-0008/#programming-recommendations):

> Comparisons to singletons like None should always be done with is or is not, never the equality operators.


Full diff: https://github.com/llvm/llvm-project/pull/94018.diff

5 Files Affected:

  • (modified) llvm/utils/indirect_calls.py (+1-1)
  • (modified) llvm/utils/lit/lit/TestRunner.py (+1-1)
  • (modified) llvm/utils/lit/lit/util.py (+1-1)
  • (modified) llvm/utils/schedcover.py (+1-1)
  • (modified) llvm/utils/shuffle_select_fuzz_tester.py (+6-6)
diff --git a/llvm/utils/indirect_calls.py b/llvm/utils/indirect_calls.py
index 2bdabc8c4d74f..34d9e8f9422b0 100755
--- a/llvm/utils/indirect_calls.py
+++ b/llvm/utils/indirect_calls.py
@@ -34,7 +34,7 @@ def look_for_indirect(file):
         if line.startswith(" ") == False:
             function = line
         result = re.search("(call|jmp).*\*", line)
-        if result != None:
+        if result is not None:
             # TODO: Perhaps use cxxfilt to demangle functions?
             print(function)
             print(line)
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index da7fa86fd3917..a6f1a46f09c86 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -197,7 +197,7 @@ def executeShCmd(cmd, shenv, results, timeout=0):
     timeout
     """
     # Use the helper even when no timeout is required to make
-    # other code simpler (i.e. avoid bunch of ``!= None`` checks)
+    # other code simpler (i.e. avoid bunch of ``is not None`` checks)
     timeoutHelper = TimeoutHelper(timeout)
     if timeout > 0:
         timeoutHelper.startTimer()
diff --git a/llvm/utils/lit/lit/util.py b/llvm/utils/lit/lit/util.py
index 232ddc9171ad3..a2452f5566b77 100644
--- a/llvm/utils/lit/lit/util.py
+++ b/llvm/utils/lit/lit/util.py
@@ -408,7 +408,7 @@ def killProcess():
         out, err = p.communicate(input=input)
         exitCode = p.wait()
     finally:
-        if timerObject != None:
+        if timerObject is not None:
             timerObject.cancel()
 
     # Ensure the resulting output is always of string type.
diff --git a/llvm/utils/schedcover.py b/llvm/utils/schedcover.py
index 41d0359462d19..caa73b6d6a747 100755
--- a/llvm/utils/schedcover.py
+++ b/llvm/utils/schedcover.py
@@ -25,7 +25,7 @@ def add(instr, model, resource=None):
 def filter_model(m):
     global filt
     if m and filt:
-        return filt.search(m) != None
+        return filt.search(m) is not None
     else:
         return True
 
diff --git a/llvm/utils/shuffle_select_fuzz_tester.py b/llvm/utils/shuffle_select_fuzz_tester.py
index 73bac3c18db14..f51945b530d3f 100755
--- a/llvm/utils/shuffle_select_fuzz_tester.py
+++ b/llvm/utils/shuffle_select_fuzz_tester.py
@@ -157,7 +157,7 @@ def dump(self):
         )
 
     def calc_value(self):
-        if self.value != None:
+        if self.value is not None:
             print("Trying to calculate the value of a shuffle instruction twice")
             exit(1)
 
@@ -199,7 +199,7 @@ def dump(self):
         )
 
     def calc_value(self):
-        if self.value != None:
+        if self.value is not None:
             print("Trying to calculate the value of a select instruction twice")
             exit(1)
 
@@ -237,7 +237,7 @@ def gen_inputs(ty, num):
 # In case one of the dimensions (scalar type/number of elements) is provided,
 # fill the blank dimension and return appropriate Type object.
 def get_random_type(ty, num_elts):
-    if ty != None:
+    if ty is not None:
         if ty == "i8":
             is_float = False
             width = 8
@@ -260,10 +260,10 @@ def get_random_type(ty, num_elts):
     int_elt_widths = [8, 16, 32, 64]
     float_elt_widths = [32, 64]
 
-    if num_elts == None:
+    if num_elts is None:
         num_elts = random.choice(range(2, 65))
 
-    if ty == None:
+    if ty is None:
         # 1 for integer type, 0 for floating-point
         if random.randint(0, 1):
             is_float = False
@@ -388,7 +388,7 @@ def main():
     ), "Minimum value greater than maximum."
     assert args.type in [None, "i8", "i16", "i32", "i64", "f32", "f64"], "Illegal type."
     assert (
-        args.num_elts == None or args.num_elts > 0
+        args.num_elts is None or args.num_elts > 0
     ), "num_elts must be a positive integer."
 
     random.seed(args.seed)

Copy link

⚠️ We detected that you are using a GitHub private e-mail address to contribute to the repo.
Please turn off Keep my email addresses private setting in your account.
See LLVM Discourse for more information.

@e-kwsm
Copy link
Contributor Author

e-kwsm commented Jun 2, 2024

⚠️ We detected that you are using a GitHub private e-mail address to contribute to the repo.
Please turn off Keep my email addresses private setting in your account.
See LLVM Discourse for more information.

Done.

Copy link
Contributor

@RoboTux RoboTux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jroelofs
Copy link
Contributor

@e-kwsm do you need us to press the "merge" button for you?

from PEP8 (https://peps.python.org/pep-0008/#programming-recommendations):

> Comparisons to singletons like None should always be done with is or
> is not, never the equality operators.
@e-kwsm
Copy link
Contributor Author

e-kwsm commented Aug 28, 2024

do you need us to press the "merge" button for you?

Yes.

@RoboTux RoboTux merged commit 94ed47f into llvm:main Aug 28, 2024
8 checks passed
Copy link

@e-kwsm Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@e-kwsm e-kwsm deleted the llvm/E711 branch August 28, 2024 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants