From 90bc1cf22f2790cada59404f5f6dedb9e9656b20 Mon Sep 17 00:00:00 2001 From: Thanos <111999343+Sachaa-Thanasius@users.noreply.github.com> Date: Wed, 12 Mar 2025 14:50:31 -0400 Subject: [PATCH 1/2] Make sure type(None) is used instead of None for the type argument of isinstance. Using None, whether alone or in a tuple, as the second argument raises a TypeError. --- distutils/compilers/C/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/distutils/compilers/C/base.py b/distutils/compilers/C/base.py index 4767b7f3..b03455a6 100644 --- a/distutils/compilers/C/base.py +++ b/distutils/compilers/C/base.py @@ -237,7 +237,7 @@ def _is_valid_macro(name, value=None): """ A valid macro is a ``name : str`` and a ``value : str | None``. """ - return isinstance(name, str) and isinstance(value, (str, None)) + return isinstance(name, str) and isinstance(value, (str, type(None))) # -- Bookkeeping methods ------------------------------------------- From 55ccc6a11f1a3aa11b292bacee14abc6f13d3330 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 19 Mar 2025 19:04:07 -0400 Subject: [PATCH 2/2] Add a regression test. --- distutils/compilers/C/base.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/distutils/compilers/C/base.py b/distutils/compilers/C/base.py index b03455a6..d4641018 100644 --- a/distutils/compilers/C/base.py +++ b/distutils/compilers/C/base.py @@ -236,6 +236,9 @@ def _check_macro_definition(self, defn): def _is_valid_macro(name, value=None): """ A valid macro is a ``name : str`` and a ``value : str | None``. + + >>> Compiler._is_valid_macro('foo', None) + True """ return isinstance(name, str) and isinstance(value, (str, type(None)))