[Scons-users] Environment.MergeFlags() modifies its arguments - bug or working as intended?

Mats Wichmann mats at wichmann.us
Wed May 20 15:06:02 EDT 2020


On 5/20/20 11:24 AM, Ionuț Leonte wrote:

orig:

>         'CFLAGS': ['-pipe', '-pthread', '-g'],

after merge:

> {'CFLAGS': ['-pipe', '-pthread', '-g']

> As you can see, MergeFlags() will effectively reverse lists from from
> the input dictionary in-place.
> This seems to happen for any key from the input dictionary that is not
> already present in the environment.

I can reproduce from your example; I tried to add it to the unittest and
couldn't, which is odd (but a different story).

if you pass a dict to MergeFlags, it's not modified by the code, but
since the values are mutable (lists), they can indeed get modified, as
there's code like this:


        for key, value in args.items():
           ...
                    try:
                        orig = orig + value
                    except (KeyError, TypeError):
                        try:
                            add_to_orig = orig.append
                        except AttributeError:
                            value.insert(0, orig)
                            orig = value

that looks like one of those easy-to-miss-in-Python things...



More information about the Scons-users mailing list