[Scons-users] SCons eats TypeErrors in callable functions when evaluated via Subst expansion

Bill Deegan bill at baddogconsulting.com
Thu Oct 19 13:59:49 EDT 2017


Greetings,

Working with the some folks trying to move to Python 3.0 and SCons 3.0
found this difficult to debug issue:

If you have some code like this:

def foo(target, source, env, for_signature):
   raise TypeError("you won't find this bug")

# Will expand $BAR to "bar baz"
env=Environment(FOO=foo, BAR="$FOO baz")

print("Bad:%s"%env.subst('$FOO'))


When you run SCons you'll get the following output:

scons: Reading SConscript files ...
Bad:<function foo at 0x109f02320>
scons: done reading SConscript files.
scons: Building targets ...
scons: `.' is up to date.
scons: done building targets.



This is due to this code (From Subst.py)

          elif callable(s):

              try:

                  s = s(target=lvars['TARGETS'],

                       source=lvars['SOURCES'],

                       env=self.env,

                       for_signature=(self.mode != SUBST_CMD))

              except TypeError:

                  # This probably indicates that it's a callable

                  # object that doesn't match our calling arguments

                  # (like an Action).

                  if self.mode == SUBST_RAW:

                      return s

                  s = self.conv(s)

              return self.substitute(s, lvars)


Note that in the user's case the code wasn't explicitly raising a
TypeError, but had a but where that was being raised only when run with
python 3.x.


So barring any objections, I'd like to file a bug on this.

It is possible to introspect "s" in the code above to check the number and
names of the functions arguments and then allow the exception to continue
propagating.


Thoughts?


-Bill
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20171019/e57c9c4e/attachment.html>


More information about the Scons-users mailing list