File tree Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Original file line number Diff line number Diff line change
1
+ Fixed a bug where calling ``build_ext.finalize_options `` after ``define `` or
2
+ ``undef `` attributes were already set would raise an exception.
Original file line number Diff line number Diff line change @@ -266,14 +266,14 @@ def finalize_options(self) -> None: # noqa: C901
266
266
# specified by the 'define' option will be set to '1'. Multiple
267
267
# symbols can be separated with commas.
268
268
269
- if self .define :
269
+ if isinstance ( self .define , str ) :
270
270
defines = self .define .split (',' )
271
271
self .define = [(symbol , '1' ) for symbol in defines ]
272
272
273
273
# The option for macros to undefine is also a string from the
274
274
# option parsing, but has to be a list. Multiple symbols can also
275
275
# be separated with commas here.
276
- if self .undef :
276
+ if isinstance ( self .undef , str ) :
277
277
self .undef = self .undef .split (',' )
278
278
279
279
if self .swig_opts is None :
Original file line number Diff line number Diff line change @@ -178,6 +178,22 @@ def C(file):
178
178
assert example_stub .startswith (f"{ build_lib } /mypkg/__pycache__/ext1" )
179
179
assert example_stub .endswith (".pyc" )
180
180
181
+ def test_finalize_options_subclassing (self ):
182
+ """
183
+ Regression test. Check that calling build_ext.finalize_options after
184
+ define or undef attributes were already set to their final type doesn't raise.
185
+ """
186
+ extension = Extension ('spam.eggs' , ['eggs.c' ])
187
+ dist = Distribution (dict (ext_modules = [extension ]))
188
+ cmd = build_ext (dist )
189
+ cmd .define = [("MY_MACRO" , "1" )]
190
+ cmd .undef = ["EVIL_MACRO" ]
191
+
192
+ cmd .finalize_options ()
193
+
194
+ assert cmd .define == [("MY_MACRO" , "1" )]
195
+ assert cmd .undef == ["EVIL_MACRO" ]
196
+
181
197
182
198
class TestBuildExtInplace :
183
199
def get_build_ext_cmd (self , optional : bool , ** opts ) -> build_ext :
You can’t perform that action at this time.
0 commit comments