From 606a44b62ea7032f63e359aaaaabc0057e168890 Mon Sep 17 00:00:00 2001
From: niels <nkeulen@gmail.com>
Date: Wed, 27 Jan 2021 20:44:12 +0100
Subject: [PATCH] Fix for is_loopback behaviour (issue: #222) (#223)

---
 netaddr/ip/__init__.py                        |  4 +--
 .../tests/ip/test_ip_network_categories.py    | 26 +++++++++++++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)
 create mode 100644 netaddr/tests/ip/test_ip_network_categories.py

diff --git a/netaddr/ip/__init__.py b/netaddr/ip/__init__.py
index d1232eb..9e13b29 100644
--- a/netaddr/ip/__init__.py
+++ b/netaddr/ip/__init__.py
@@ -151,7 +151,7 @@ class BaseIP(object):
         if self._module.version == 4:
             return self in IPV4_LOOPBACK
         elif self._module.version == 6:
-            return self == IPV6_LOOPBACK
+            return self in IPV6_LOOPBACK
 
     def is_private(self):
         """
@@ -1949,7 +1949,7 @@ IPV4_RESERVED = (
 #-----------------------------------------------------------------------------
 #   Cached IPv6 address range lookups.
 #-----------------------------------------------------------------------------
-IPV6_LOOPBACK = IPAddress('::1')
+IPV6_LOOPBACK = IPNetwork('::1/128')
 
 IPV6_PRIVATE = (
     IPNetwork('fc00::/7'),  #   Unique Local Addresses (ULA)
diff --git a/netaddr/tests/ip/test_ip_network_categories.py b/netaddr/tests/ip/test_ip_network_categories.py
new file mode 100644
index 0000000..9f9961e
--- /dev/null
+++ b/netaddr/tests/ip/test_ip_network_categories.py
@@ -0,0 +1,26 @@
+from netaddr import IPNetwork
+
+
+def test_is_unicast():
+    assert IPNetwork('192.0.2.0/24').is_unicast()
+    assert IPNetwork('fe80::1/48').is_unicast()
+
+
+def test_is_multicast():
+    assert IPNetwork('239.192.0.1/24').is_multicast()
+    assert IPNetwork('ff00::/8').is_multicast()
+
+
+def test_is_private():
+    assert IPNetwork('10.0.0.0/24').is_private()
+    assert IPNetwork('fc00::/7').is_private()
+
+
+def test_is_reserved():
+    assert IPNetwork('240.0.0.0/24').is_reserved()
+    assert IPNetwork('0::/48').is_reserved()
+
+
+def test_is_loopback():
+    assert IPNetwork('127.0.0.0/8').is_loopback()
+    assert IPNetwork('::1/128').is_loopback()
-- 
2.33.0

