[Scons-users] env.Dictionary bug? doc problem?

Mats Wichmann mats at wichmann.us
Sun Jul 22 14:18:15 EDT 2018


=== manpage:

 env.Dictionary([vars])

    Returns a dictionary object containing copies of all of the
construction variables in the environment. If there are any variable
names specified, only the specified construction variables are returned
in the dictionary.

    Example:

    dict = env.Dictionary()
    cc_dict = env.Dictionary('CC', 'CCFLAGS', 'CCCOM')


But testing exactly that example -

=== SConstruct:
env = Environment()
dict = env.Dictionary()
print("dict: " + str(type(dict)))
cc_dict = env.Dictionary('CC', 'CCFLAGS', 'CCCOM')
print("cc_dict: " + str(type(cc_dict)))
print(cc_dict)

=== output:
scons: Reading SConscript files ...
dict: <type 'dict'>
cc_dict: <type 'list'>
['gcc', [], '$CC -o $TARGET -c $CFLAGS $CCFLAGS $_CCCOMCOM $SOURCES']
scons: done reading SConscript files.


And that's pretty easy to see in the code, which uses a list
comprehension if there are arguments, extracting only the values and
ignoring the keys.

    def Dictionary(self, *args):
        if not args:
            return self._dict
        dlist = [self._dict[x] for x in args]
        if len(dlist) == 1:
            dlist = dlist[0]
        return dlist

If the documentation is correct, what we really want is a "dictionary
slicing" type of operation (maybe using itertools, maybe using a
dictionary view object).



More information about the Scons-users mailing list