Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Lib/ipaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@


import functools
import types

IPV4LENGTH = 32
IPV6LENGTH = 128
Expand Down Expand Up @@ -1124,6 +1125,7 @@ def is_loopback(self):
return (self.network_address.is_loopback and
self.broadcast_address.is_loopback)

__class_getitem__ = classmethod(types.GenericAlias)

class _BaseV4:

Expand Down Expand Up @@ -1444,6 +1446,8 @@ def with_hostmask(self):
return '%s/%s' % (self._string_from_ip_int(self._ip),
self.hostmask)

__class_getitem__ = classmethod(types.GenericAlias)


class IPv4Network(_BaseV4, _BaseNetwork):

Expand Down Expand Up @@ -2152,6 +2156,8 @@ def is_unspecified(self):
def is_loopback(self):
return self._ip == 1 and self.network.is_loopback

__class_getitem__ = classmethod(types.GenericAlias)


class IPv6Network(_BaseV6, _BaseNetwork):

Expand Down
8 changes: 6 additions & 2 deletions Lib/test/test_genericalias.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
)
from collections.abc import *
from contextlib import AbstractContextManager, AbstractAsyncContextManager
from ipaddress import IPv4Network, IPv4Interface, IPv6Network, IPv6Interface
from os import DirEntry
from re import Pattern, Match
from types import GenericAlias, MappingProxyType
Expand Down Expand Up @@ -35,8 +36,11 @@ def test_subscriptable(self):
Mapping, MutableMapping, MappingView,
KeysView, ItemsView, ValuesView,
Sequence, MutableSequence,
MappingProxyType, DirEntry
):
MappingProxyType,
DirEntry,
IPv4Network, IPv4Interface,
IPv6Network, IPv6Interface
Comment thread
gvanrossum marked this conversation as resolved.
Outdated
):
tname = t.__name__
with self.subTest(f"Testing {tname}"):
alias = t[int]
Expand Down