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

[feature request] Type compatibility with ipaddress #201

Open
johnnybubonic opened this issue Mar 23, 2020 · 4 comments
Open

[feature request] Type compatibility with ipaddress #201

johnnybubonic opened this issue Mar 23, 2020 · 4 comments

Comments

@johnnybubonic
Copy link

Hi! With python 3.x (and MAYBE 2.7?), ipaddress is now a standard library.

It'd be great if netaddr could parse those objects into native objects(A) and have a native library object attribute(B), e.g.:

#!/usr/bin/env python3

import ipaddress
import netaddr

ip4 = ipaddress.ip_address('192.0.2.1')  # instance of ipaddress.IPv4Address
ip6 = ipaddress.ip_address('2001:DB8::1')  # instance of ipaddress.IPv6Address
net4 = ipaddress.ip_network('192.0.2.0/24')  # instance of ipaddress.IPv4Network
net6 = ipaddress.ip_network('2001:DB8::/32')  # instance of ipaddress.IPv6Network

# "A"
n_ip4 = netaddr.IPAddress(ip4)  # instance of netaddr.ip.IPAddress using above
n_ip6 = netaddr.IPAddress(ip6)  # instance of netaddr.ip.IPAddress using above
n_net4 = netaddr.IPNetwork(net4)  # instance of netaddr.ip.IPNetwork using above
n_net6 = netaddr.IPNetwork(net6)  # instance of netaddr.ip.IPNetwork using above

# "B"
isinstance(n_ip4.ipaddress, ipaddress.IPv4Address)  # This attribute would exist and this test would be True.

Thoughts?

@johnnybubonic
Copy link
Author

johnnybubonic commented Mar 23, 2020

A should be fairly easy; the str() conversion for ipaddress.IPv4Address/ipaddress.IPv6Address is the string representation that netaddr.IPAddress() accepts.

LIkewise, for ipaddress.IPv4Network/ipaddress.IPv6Network str() conversions, it's in the standard network/prefix format (e.g. 192.0.2.0/24).

@jstasiak
Copy link
Contributor

I agree, looks convenient.

@KOLANICH
Copy link
Contributor

Since ipaddress is in the standard library, how about removing the impl duplicating the impl there and just reuse the impl that is already in the standard library?

@jstasiak
Copy link
Contributor

I'm happy to accept a pull request that keeps the current interface but reuses the standard library implementation (Python 3.6+ is fine as we're about to drop 2.7 and 3.5 compatibility anyway).

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

No branches or pull requests

3 participants