From 2fa67df605e4b0803e7e3aac0b85d851b4b4e09a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Batuhan=20Ta=C5=9Fkaya?= Date: Fri, 10 Apr 2020 07:04:54 +0300 Subject: bpo-39481: PEP 585 for ipaddress.py (GH-19418) --- Lib/ipaddress.py | 6 ++++++ Lib/test/test_genericalias.py | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py index ac1143a..439f241 100644 --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -12,6 +12,7 @@ __version__ = '1.0' import functools +import types IPV4LENGTH = 32 IPV6LENGTH = 128 @@ -1124,6 +1125,7 @@ class _BaseNetwork(_IPAddressBase): return (self.network_address.is_loopback and self.broadcast_address.is_loopback) + __class_getitem__ = classmethod(types.GenericAlias) class _BaseV4: @@ -1444,6 +1446,8 @@ class IPv4Interface(IPv4Address): return '%s/%s' % (self._string_from_ip_int(self._ip), self.hostmask) + __class_getitem__ = classmethod(types.GenericAlias) + class IPv4Network(_BaseV4, _BaseNetwork): @@ -2152,6 +2156,8 @@ class IPv6Interface(IPv6Address): def is_loopback(self): return self._ip == 1 and self.network.is_loopback + __class_getitem__ = classmethod(types.GenericAlias) + class IPv6Network(_BaseV6, _BaseNetwork): diff --git a/Lib/test/test_genericalias.py b/Lib/test/test_genericalias.py index d8acdee..535c249 100644 --- a/Lib/test/test_genericalias.py +++ b/Lib/test/test_genericalias.py @@ -7,6 +7,7 @@ from collections import ( ) from collections.abc import * from contextlib import AbstractContextManager, AbstractAsyncContextManager +from ipaddress import IPv4Network, IPv4Interface, IPv6Network, IPv6Interface from itertools import chain from os import DirEntry from re import Pattern, Match @@ -36,6 +37,9 @@ class BaseTest(unittest.TestCase): Mapping, MutableMapping, MappingView, KeysView, ItemsView, ValuesView, Sequence, MutableSequence, + MappingProxyType, + DirEntry, + IPv4Network, IPv4Interface, IPv6Network, IPv6Interface, MappingProxyType, DirEntry, chain, ): -- cgit v0.12