From 46bfd61576b80be0443c40f828cbe66869706a73 Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Thu, 18 Nov 2021 17:37:47 +0100 Subject: [PATCH] Remove return code type check. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only floating-point objects have an is_integer method (cf. https://docs.python.org/3.10/library/stdtypes.html#typesnumeric), so this will actually raise an AttributeError whenever the main function returns an integer or None. sys.exit works just fine with any argument type, so there’s no need to check anything. The example at https://packaging.python.org/specifications/entry-points/#use-for-scripts also doesn’t contain a type check. --- python/pip_install/extract_wheels/lib/bazel.py | 3 +-- python/pip_install/extract_wheels/lib/bazel_test.py | 8 ++------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/python/pip_install/extract_wheels/lib/bazel.py b/python/pip_install/extract_wheels/lib/bazel.py index 433a9ea54a..1ea4a7b77a 100644 --- a/python/pip_install/extract_wheels/lib/bazel.py +++ b/python/pip_install/extract_wheels/lib/bazel.py @@ -35,8 +35,7 @@ def generate_entry_point_contents(entry_point: str, shebang: str = "#!/usr/bin/e from {module} import {method} if __name__ == "__main__": rc = {method}() - if rc.is_integer(): - sys.exit(rc) + sys.exit({method}()) """.format( shebang=shebang, module=module, diff --git a/python/pip_install/extract_wheels/lib/bazel_test.py b/python/pip_install/extract_wheels/lib/bazel_test.py index 97bc06e779..5c22047479 100644 --- a/python/pip_install/extract_wheels/lib/bazel_test.py +++ b/python/pip_install/extract_wheels/lib/bazel_test.py @@ -10,9 +10,7 @@ def test_generate_entry_point_contents(self): import sys from sphinx.cmd.build import main if __name__ == "__main__": - rc = main() - if rc.is_integer(): - sys.exit(rc) + sys.exit(main()) """ self.assertEqual(got, want) @@ -22,8 +20,6 @@ def test_generate_entry_point_contents_with_shebang(self): want = """#!/usr/bin/python import sys from sphinx.cmd.build import main -rc = main() -if rc.is_integer(): - sys.exit(rc) +sys.exit(main()) """ self.assertEqual(got, want)