[New-bugs-announce] [issue35338] set union/intersection/difference could accept zero arguments

David Miguel Susano Pinto report at bugs.python.org
Wed Nov 28 09:50:55 EST 2018


New submission from David Miguel Susano Pinto <carandraug+dev at gmail.com>:

set union, intersection, difference methods accept any non-zero number of sets and return a new set instance, like so:

    >>> a = set([1, 2])
    >>> b = set([1, 3])
    >>> c = set([3, 5])
    >>> set.union(a, b, c)
    {1, 2, 3, 5}

even if it's only one argument:

    >>> set.union(a)
    {1, 2}

I think it would be nice if zero arguments were not an error:

    >>> set.union()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: descriptor 'union' of 'set' object needs an argument

This would allow to handle any sequence of sets which otherwise requires this:

    if len(sequence):
        return set.union(*sequence)
    else:
        return set()

----------
messages: 330601
nosy: carandraug
priority: normal
severity: normal
status: open
title: set union/intersection/difference could accept zero arguments
type: enhancement
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35338>
_______________________________________


More information about the New-bugs-announce mailing list