Skip to content
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

Passing list of IPRange objects to IPSet Fails #121

Open
shepherdjay opened this issue Jan 5, 2016 · 1 comment
Open

Passing list of IPRange objects to IPSet Fails #121

shepherdjay opened this issue Jan 5, 2016 · 1 comment

Comments

@shepherdjay
Copy link

While it appears you can mix/match a list of IPNetwork and IPAddress objects into IPSet for construction you cannot pass a list that contains an IPRange object. This leads to an asymmetry when handling large datasets that contain multiple of each type.

Working Examples

>>> my_set = IPSet([IPNetwork('10.0.0.0/24'), IPNetwork('192.168.1.0/24')])
>>> my_set
IPSet(['10.0.0.0/24', '192.168.1.0/24'])
>>> my_set = IPSet([IPNetwork('1234::/32'), IPAddress('192.0.2.0')])
>>> my_set
IPSet(['192.0.2.0/32', '1234::/32'])
>>> my_set = IPSet(IPRange('10.0.0.0', "10.0.1.31"))
>>> my_set
IPSet(['10.0.0.0/24', '10.0.1.0/27'])

Attempts to add any range objects if they are part of a set fail. Even if all objects in list are range type.

>>> my_set = IPSet([IPRange('10.0.0.0', "10.0.1.31"), IPRange('192.168.1.0', '192.168.1.5')])
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Program Files (x86)\Python 3.5\lib\site-packages\netaddr\ip\sets.py", line 121, in __init__
    for cidr in cidr_merge(mergeable):
  File "C:\Program Files (x86)\Python 3.5\lib\site-packages\netaddr\ip\__init__.py", line 1549, in cidr_merge
    cidr = IPNetwork(ip)
  File "C:\Program Files (x86)\Python 3.5\lib\site-packages\netaddr\ip\__init__.py", line 923, in __init__
    implicit_prefix, flags)
  File "C:\Program Files (x86)\Python 3.5\lib\site-packages\netaddr\ip\__init__.py", line 818, in parse_ip_network
    raise TypeError('unexpected type %s for addr arg' % type(addr))
TypeError: unexpected type <class 'netaddr.ip.IPRange'> for addr arg

This same error type is reported when adding a mixed set of object types if one of those types include an IPRange or when passing a list of a single IPRange object.

@jstasiak
Copy link
Contributor

Looks like a legitimate bug, needs fixing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants