@@ -26,12 +26,14 @@ class Extension:
26
26
name : string
27
27
the full name of the extension, including any packages -- ie.
28
28
*not* a filename or pathname, but Python dotted name
29
- sources : [string | os.PathLike]
30
- list of source filenames, relative to the distribution root
31
- (where the setup script lives), in Unix form (slash-separated)
32
- for portability. Source files may be C, C++, SWIG (.i),
33
- platform-specific resource files, or whatever else is recognized
34
- by the "build_ext" command as source for a Python extension.
29
+ sources : Iterable[string | os.PathLike]
30
+ iterable of source filenames (except strings, which could be misinterpreted
31
+ as a single filename), relative to the distribution root (where the setup
32
+ script lives), in Unix form (slash-separated) for portability. Can be any
33
+ non-string iterable (list, tuple, set, etc.) containing strings or
34
+ PathLike objects. Source files may be C, C++, SWIG (.i), platform-specific
35
+ resource files, or whatever else is recognized by the "build_ext" command
36
+ as source for a Python extension.
35
37
include_dirs : [string]
36
38
list of directories to search for C/C++ header files (in Unix
37
39
form for portability)
@@ -106,12 +108,23 @@ def __init__(
106
108
):
107
109
if not isinstance (name , str ):
108
110
raise AssertionError ("'name' must be a string" ) # noqa: TRY004
109
- if not (
110
- isinstance (sources , list )
111
- and all (isinstance (v , (str , os .PathLike )) for v in sources )
112
- ):
111
+
112
+ # we handle the string case first; though strings are iterable, we disallow them
113
+ if isinstance (sources , str ):
114
+ raise AssertionError ( # noqa: TRY004
115
+ "'sources' must be an iterable of strings or PathLike objects, not a string"
116
+ )
117
+
118
+ # mow we check if it's iterable and contains valid types
119
+ try :
120
+ sources = list (sources ) # convert to list for consistency
121
+ if not all (isinstance (v , (str , os .PathLike )) for v in sources ):
122
+ raise AssertionError (
123
+ "All elements in 'sources' must be strings or PathLike objects"
124
+ )
125
+ except TypeError :
113
126
raise AssertionError (
114
- "'sources' must be a list of strings or PathLike objects. "
127
+ "'sources' must be an iterable of strings or PathLike objects"
115
128
)
116
129
117
130
self .name = name
0 commit comments