Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3f1c9a9

Browse files
committed
Allow unknown keyword arguments to the Extension class, and warn about them.
1 parent cd58b8f commit 3f1c9a9

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

Lib/distutils/extension.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
import os, string
1111
from types import *
1212

13+
try:
14+
import warnings
15+
except ImportError:
16+
warnings = None
1317

1418
# This class is really only used by the "build_ext" command, so it might
1519
# make sense to put it in distutils.command.build_ext. However, that
@@ -93,8 +97,8 @@ def __init__ (self, name, sources,
9397
export_symbols=None,
9498
depends=None,
9599
language=None,
100+
**kw # To catch unknown keywords
96101
):
97-
98102
assert type(name) is StringType, "'name' must be a string"
99103
assert (type(sources) is ListType and
100104
map(type, sources) == [StringType]*len(sources)), \
@@ -115,6 +119,15 @@ def __init__ (self, name, sources,
115119
self.depends = depends or []
116120
self.language = language
117121

122+
# If there are unknown keyword options, warn about them
123+
if len(kw):
124+
L = kw.keys() ; L.sort()
125+
L = map(repr, L)
126+
msg = "Unknown Extension options: " + string.join(L, ', ')
127+
if warnings is not None:
128+
warnings.warn(msg)
129+
else:
130+
sys.stderr.write(msg + '\n')
118131
# class Extension
119132

120133

0 commit comments

Comments
 (0)