@@ -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)
@@ -105,17 +107,23 @@ def __init__(
105
107
** kw , # To catch unknown keywords
106
108
):
107
109
if not isinstance (name , str ):
108
- 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
- ):
113
- raise AssertionError (
114
- "'sources' must be a list of strings or PathLike objects."
110
+ raise TypeError ("'name' must be a string" ) # noqa: TRY004
111
+
112
+ # handle the string case first; since strings are iterable, disallow them
113
+ if isinstance (sources , str ):
114
+ raise TypeError (
115
+ "'sources' must be an iterable of strings or PathLike objects, not a string"
116
+ )
117
+
118
+ # now we check if it's iterable and contains valid types
119
+ try :
120
+ self .sources = list (map (os .fspath , sources ))
121
+ except TypeError :
122
+ raise TypeError (
123
+ "'sources' must be an iterable of strings or PathLike objects"
115
124
)
116
125
117
126
self .name = name
118
- self .sources = list (map (os .fspath , sources ))
119
127
self .include_dirs = include_dirs or []
120
128
self .define_macros = define_macros or []
121
129
self .undef_macros = undef_macros or []
0 commit comments