Skip to content

Commit d003758

Browse files
committed
chore: remove legacy code <py39
1 parent bd84538 commit d003758

4 files changed

Lines changed: 8 additions & 30 deletions

File tree

src/zeroconf/_services/info.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import asyncio
2424
import random
25-
import sys
2625
from typing import TYPE_CHECKING, Dict, List, Optional, Set, Union, cast
2726

2827
from .._cache import DNSCache
@@ -77,8 +76,6 @@
7776
_TYPE_TXT,
7877
)
7978

80-
IPADDRESS_SUPPORTS_SCOPE_ID = sys.version_info >= (3, 9, 0)
81-
8279
_IPVersion_All_value = IPVersion.All.value
8380
_IPVersion_V4Only_value = IPVersion.V4Only.value
8481
# https://datatracker.ietf.org/doc/html/rfc6762#section-5.2
@@ -250,7 +247,7 @@ def addresses(self, value: List[bytes]) -> None:
250247
self._get_address_and_nsec_records_cache = None
251248

252249
for address in value:
253-
if IPADDRESS_SUPPORTS_SCOPE_ID and len(address) == 16 and self.interface_index is not None:
250+
if len(address) == 16 and self.interface_index is not None:
254251
addr = ip_bytes_and_scope_to_address(address, self.interface_index)
255252
else:
256253
addr = cached_ip_addresses(address)

src/zeroconf/_utils/ipaddress.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,15 @@
2020
USA
2121
"""
2222

23-
import sys
24-
from functools import lru_cache
23+
from functools import cache, lru_cache
2524
from ipaddress import AddressValueError, IPv4Address, IPv6Address, NetmaskValueError
2625
from typing import Any, Optional, Union
2726

2827
from .._dns import DNSAddress
2928
from ..const import _TYPE_AAAA
3029

31-
if sys.version_info >= (3, 9, 0):
32-
from functools import cache
33-
else:
34-
cache = lru_cache(maxsize=None)
35-
3630
bytes_ = bytes
3731
int_ = int
38-
IPADDRESS_SUPPORTS_SCOPE_ID = sys.version_info >= (3, 9, 0)
3932

4033

4134
class ZeroconfIPv4Address(IPv4Address):
@@ -128,7 +121,7 @@ def get_ip_address_object_from_record(
128121
record: DNSAddress,
129122
) -> Optional[Union[ZeroconfIPv4Address, ZeroconfIPv6Address]]:
130123
"""Get the IP address object from the record."""
131-
if IPADDRESS_SUPPORTS_SCOPE_ID and record.type == _TYPE_AAAA and record.scope_id:
124+
if record.type == _TYPE_AAAA and record.scope_id:
132125
return ip_bytes_and_scope_to_address(record.address, record.scope_id)
133126
return cached_ip_addresses_wrapper(record.address)
134127

@@ -146,7 +139,7 @@ def ip_bytes_and_scope_to_address(
146139

147140
def str_without_scope_id(addr: Union[ZeroconfIPv4Address, ZeroconfIPv6Address]) -> str:
148141
"""Return the string representation of the address without the scope id."""
149-
if IPADDRESS_SUPPORTS_SCOPE_ID and addr.version == 6:
142+
if addr.version == 6:
150143
address_str = str(addr)
151144
return address_str.partition("%")[0]
152145
return str(addr)

tests/services/test_info.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import logging
88
import os
99
import socket
10-
import sys
1110
import threading
1211
import unittest
1312
from ipaddress import ip_address
@@ -704,7 +703,6 @@ def test_multiple_addresses():
704703
assert info.addresses == [address, address]
705704
assert info.parsed_addresses() == [address_parsed, address_parsed]
706705
assert info.parsed_scoped_addresses() == [address_parsed, address_parsed]
707-
ipaddress_supports_scope_id = sys.version_info >= (3, 9, 0)
708706

709707
if has_working_ipv6() and not os.environ.get("SKIP_IPV6"):
710708
address_v6_parsed = "2001:db8::1"
@@ -751,9 +749,7 @@ def test_multiple_addresses():
751749
assert info.ip_addresses_by_version(r.IPVersion.All) == [
752750
ip_address(address),
753751
ip_address(address_v6),
754-
ip_address(address_v6_ll_scoped_parsed)
755-
if ipaddress_supports_scope_id
756-
else ip_address(address_v6_ll),
752+
ip_address(address_v6_ll_scoped_parsed),
757753
]
758754
assert info.addresses_by_version(r.IPVersion.V4Only) == [address]
759755
assert info.ip_addresses_by_version(r.IPVersion.V4Only) == [ip_address(address)]
@@ -763,9 +759,7 @@ def test_multiple_addresses():
763759
]
764760
assert info.ip_addresses_by_version(r.IPVersion.V6Only) == [
765761
ip_address(address_v6),
766-
ip_address(address_v6_ll_scoped_parsed)
767-
if ipaddress_supports_scope_id
768-
else ip_address(address_v6_ll),
762+
ip_address(address_v6_ll_scoped_parsed),
769763
]
770764
assert info.parsed_addresses() == [
771765
address_parsed,
@@ -780,16 +774,15 @@ def test_multiple_addresses():
780774
assert info.parsed_scoped_addresses() == [
781775
address_parsed,
782776
address_v6_parsed,
783-
address_v6_ll_scoped_parsed if ipaddress_supports_scope_id else address_v6_ll_parsed,
777+
address_v6_ll_scoped_parsed,
784778
]
785779
assert info.parsed_scoped_addresses(r.IPVersion.V4Only) == [address_parsed]
786780
assert info.parsed_scoped_addresses(r.IPVersion.V6Only) == [
787781
address_v6_parsed,
788-
address_v6_ll_scoped_parsed if ipaddress_supports_scope_id else address_v6_ll_parsed,
782+
address_v6_ll_scoped_parsed,
789783
]
790784

791785

792-
@unittest.skipIf(sys.version_info < (3, 9, 0), "Requires newer python")
793786
def test_scoped_addresses_from_cache():
794787
type_ = "_http._tcp.local."
795788
registration_name = f"scoped.{type_}"

tests/utils/test_ipaddress.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
"""Unit tests for zeroconf._utils.ipaddress."""
44

5-
import sys
6-
7-
import pytest
8-
95
from zeroconf import const
106
from zeroconf._dns import DNSAddress
117
from zeroconf._utils import ipaddress
@@ -52,7 +48,6 @@ def test_cached_ip_addresses_wrapper():
5248
assert ipv6.is_unspecified is True
5349

5450

55-
@pytest.mark.skipif(sys.version_info < (3, 9, 0), reason="scope_id is not supported")
5651
def test_get_ip_address_object_from_record():
5752
"""Test the get_ip_address_object_from_record."""
5853
# not link local

0 commit comments

Comments
 (0)