Skip to content

Commit 2fa67df

Browse files
authored
bpo-39481: PEP 585 for ipaddress.py (GH-19418)
1 parent a8403d0 commit 2fa67df

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

Lib/ipaddress.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313

1414
import functools
15+
import types
1516

1617
IPV4LENGTH = 32
1718
IPV6LENGTH = 128
@@ -1124,6 +1125,7 @@ def is_loopback(self):
11241125
return (self.network_address.is_loopback and
11251126
self.broadcast_address.is_loopback)
11261127

1128+
__class_getitem__ = classmethod(types.GenericAlias)
11271129

11281130
class _BaseV4:
11291131

@@ -1444,6 +1446,8 @@ def with_hostmask(self):
14441446
return '%s/%s' % (self._string_from_ip_int(self._ip),
14451447
self.hostmask)
14461448

1449+
__class_getitem__ = classmethod(types.GenericAlias)
1450+
14471451

14481452
class IPv4Network(_BaseV4, _BaseNetwork):
14491453

@@ -2152,6 +2156,8 @@ def is_unspecified(self):
21522156
def is_loopback(self):
21532157
return self._ip == 1 and self.network.is_loopback
21542158

2159+
__class_getitem__ = classmethod(types.GenericAlias)
2160+
21552161

21562162
class IPv6Network(_BaseV6, _BaseNetwork):
21572163

Lib/test/test_genericalias.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
)
88
from collections.abc import *
99
from contextlib import AbstractContextManager, AbstractAsyncContextManager
10+
from ipaddress import IPv4Network, IPv4Interface, IPv6Network, IPv6Interface
1011
from itertools import chain
1112
from os import DirEntry
1213
from re import Pattern, Match
@@ -36,6 +37,9 @@ def test_subscriptable(self):
3637
Mapping, MutableMapping, MappingView,
3738
KeysView, ItemsView, ValuesView,
3839
Sequence, MutableSequence,
40+
MappingProxyType,
41+
DirEntry,
42+
IPv4Network, IPv4Interface, IPv6Network, IPv6Interface,
3943
MappingProxyType, DirEntry,
4044
chain,
4145
):

0 commit comments

Comments
 (0)