Skip to content

Commit 2c86616

Browse files
committed
Extract method for checking macro definition.
1 parent 7a9818b commit 2c86616

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

distutils/ccompiler.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -188,23 +188,26 @@ def _find_macro(self, name):
188188
return None
189189

190190
def _check_macro_definitions(self, definitions):
191-
"""Ensures that every element of 'definitions' is a valid macro
192-
definition, ie. either (name,value) 2-tuple or a (name,) tuple. Do
193-
nothing if all definitions are OK, raise TypeError otherwise.
194-
"""
191+
"""Ensure that every element of 'definitions' is valid."""
195192
for defn in definitions:
196-
if not (
197-
isinstance(defn, tuple)
198-
and (
199-
len(defn) in (1, 2)
200-
and (isinstance(defn[1], str) or defn[1] is None)
201-
)
202-
and isinstance(defn[0], str)
203-
):
204-
raise TypeError(
205-
f"invalid macro definition '{defn}': "
206-
"must be tuple (string,), (string, string), or (string, None)"
207-
)
193+
self._check_macro_definition(defn)
194+
195+
def _check_macro_definition(self, defn):
196+
"""
197+
Raise a TypeError if defn is not valid.
198+
199+
A valid definition is either a (name, value) 2-tuple or a (name,) tuple.
200+
"""
201+
valid = (
202+
isinstance(defn, tuple)
203+
and (len(defn) in (1, 2) and (isinstance(defn[1], str) or defn[1] is None))
204+
and isinstance(defn[0], str)
205+
)
206+
if not valid:
207+
raise TypeError(
208+
f"invalid macro definition '{defn}': "
209+
"must be tuple (string,), (string, string), or (string, None)"
210+
)
208211

209212
# -- Bookkeeping methods -------------------------------------------
210213

0 commit comments

Comments
 (0)