Author josh.r
Recipients SilentGhost, carandraug, josh.r, mark.dickinson, remi.lapeyre, rhettinger, xtreak
Date 2018-11-30.15:26:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
set.union() without constructing the set you call union on only happens to work for the set.union(a) case because `a` is already a set. union takes arbitrary iterables, not just sets, and you're just cheating by explicitly passing `a` as the expected self argument. If you'd set `a = [1, 2]` (a list, not a set), set.union(a) would fail, because set.union(a) was only working by accident of a being interpreted as self; any such use is misuse.

Point is, the zero args case isn't a unique corner case;


fails too, because the first argument is interpreted as self, and must be a set for this to work.

SilentGhost's solution of constructing the set before union-ing via set().union(*args) is the correct solution; it's free of corner cases, removing the specialness of the first element in args (because self is passed in correctly), and not having any troubles with empty args.

intersection is the only interesting case here, where preconstruction of the empty set doesn't work, because that would render the result the empty set unconditionally. The solution there is set(args[0]).intersection(*args) (or *args[1:]), but that's obviously uglier.

I'm -1 on making any changes to set.union to support this misuse case.
Date User Action Args
2018-11-30 15:26:10josh.rsetrecipients: + josh.r, rhettinger, mark.dickinson, SilentGhost, remi.lapeyre, xtreak, carandraug
2018-11-30 15:26:10josh.rsetmessageid: <>
2018-11-30 15:26:10josh.rlinkissue35338 messages
2018-11-30 15:26:10josh.rcreate