-
-
Notifications
You must be signed in to change notification settings - Fork 310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SCons.Util.Flatten doesn't work for nested sets, None #4393
Comments
@mwichmann Isn't the implementation behavior for None correct and the test expectation incorrect? The docstring contains:
|
The behavior for sets is probably also correct as a set is not a sequence (i.e., sets cannot be indexed and are not ordered). A namedtuple is a sequence and would be expanded/flattened which in most use cases is likely undesirable. A namedtuple is probably better handled as a scalar rather than a sequence. Food for thought. Edit: namedtuple does serialize to json as a list though. |
Interesting thoughts. Will have to chew on it some more. Don't trust the docstring too much, as I've adjusted it already trying to convey what I think it does. Old manpage used to say:
And old docstring:
The implication of those in combination is unclear: one says "takes a sequence" and the other scalar or sequence. |
In the general case, a scalar or sequence argument is useful as the return value is always is a list which in certain circumstances could eliminate type-specific testing (i.e., sequence/string vs scalar) prior to invocation. For example, calling flatten to get a list of system paths. A scalar string representing a path would be converted to a list within flatten and a lists of paths would be flattened as expected. Either way the result is a list without having to check if the argument passed in is a scalar/string/sequence. Whether or not the scalar None is meaningful is context dependent. In some contexts, None might be a valid member of nested lists or as a scalar. In other cases, None might imply bad input in the code around the flatten call (which might be guarded by a test for evaluating as true: |
Not sure I agree that sets shouldn't be flattened. That said, do any of our internal datastructures use or return sets currently? |
Keep in mind what follows is intended to be helpful.
Sets probably should be flattened and/or have a boolean keyword argument indicating how sets should be processed.
I was just pointing out that the existing code type checks are for sequences. From a type perspective, sets and frozensets are not sequences which are ordered and indexible.
Above my pay grade.
Sets are useful proxies for lists as they guarantee uniqueness. A dictionary is not going to be flattened. The existing For example (annotated):
The same problem appears in At a minimum, the The script below is also attached in a zip file. The current flatten routines were renamed with names ending in Notes:
|
I have long had a rewritten set of flatten util routines (although the name may say Flatten, that's really just a wrapper to expose it in the Environment), so I was aware of the current buggy nature. They've just never risen to the point where it seemed right to push the PR.... The way the usage is pitched this needn't be terribly comprehensive - there are places where you may call things acting on nodes, which produce a list of answers, and do so in a loop, so you get a list-of-lists. My impression is that's what Flatten was written for and everything else is just stretching it, for completeness, etc. |
This diff to
UtilTests.py
illustrates non-working combos (there might be more):With this outcome:
The text was updated successfully, but these errors were encountered: