Skip to content

Commit

Permalink
Fix deprecation warning regarding ByteString
Browse files Browse the repository at this point in the history
To address deprecation of ByteString in abc and typing, use
(bytes, bytearray) or Union[bytes, bytearray] respectively.

Signed-off-by: ko-zu <[email protected]>
  • Loading branch information
ko-zu committed Jul 13, 2024
1 parent 9aa4833 commit 0ed71f5
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions publicsuffixlist/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#

import os
from collections.abc import Iterable as iterable, ByteString as bytestring
from typing import Optional, Tuple, Union, Iterable, ByteString, overload
from collections.abc import Iterable as iterable
from typing import Optional, Tuple, Union, Iterable, overload

__all__ = ["PublicSuffixList"]

Expand All @@ -21,6 +21,7 @@
PSLFILE = os.path.join(os.path.dirname(__file__), "public_suffix_list.dat")

BytesTuple = Tuple[bytes, ...]
ByteString = Union[bytes, bytearray]
Domain = Union[str, BytesTuple]
RelaxDomain = Union[str, BytesTuple, Iterable[ByteString]]
RelaxFileSource = Union[Iterable[Union[str, ByteString]], str, ByteString]
Expand All @@ -34,7 +35,7 @@ def u(s: AnyStr) -> str:


def b(s: AnyStr) -> bytes:
return bytes(s) if isinstance(s, bytestring) else s.encode(ENCODING, ERRORMODE)
return bytes(s) if isinstance(s, (bytes, bytearray)) else s.encode(ENCODING, ERRORMODE)


def encode_idn(domain: AnyStr) -> str:
Expand Down Expand Up @@ -82,7 +83,7 @@ def _parse(self, source, accept_encoded_idn, only_icann=False):
maxlabel = 0
section_is_icann = None

if isinstance(source, (str, bytestring)):
if isinstance(source, (str, bytes, bytearray)):
source = source.splitlines()

ln = 0
Expand Down Expand Up @@ -138,7 +139,7 @@ def _preparedomain(self, domain) -> Union[Tuple[str, Labels], Tuple[BytesTuple,
domain = domain[:-1]
labels = domain.lower().split(".")

elif isinstance(domain, bytestring):
elif isinstance(domain, (bytes, bytearray)):
raise TypeError("Only str, Iter[ByteString] are supported.")

elif isinstance(domain, iterable):
Expand Down

0 comments on commit 0ed71f5

Please sign in to comment.