Skip to content

Commit 031042b

Browse files
authored
Remove deprecated functions. (#235)
1 parent c2878b7 commit 031042b

File tree

2 files changed

+2
-74
lines changed

2 files changed

+2
-74
lines changed

tests/test_util.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,8 @@
11
from unittest import TestCase
22

3-
from pytest import deprecated_call, raises
3+
from pytest import raises
44

5-
from w3lib.util import (
6-
str_to_unicode,
7-
to_bytes,
8-
to_native_str,
9-
to_unicode,
10-
unicode_to_str,
11-
)
12-
13-
14-
class StrToUnicodeTestCase(TestCase):
15-
def test_deprecation(self):
16-
with deprecated_call():
17-
str_to_unicode("")
5+
from w3lib.util import to_bytes, to_unicode
186

197

208
class ToBytesTestCase(TestCase):
@@ -23,19 +11,7 @@ def test_type_error(self):
2311
to_bytes(True) # type: ignore
2412

2513

26-
class ToNativeStrTestCase(TestCase):
27-
def test_deprecation(self):
28-
with deprecated_call():
29-
to_native_str("")
30-
31-
3214
class ToUnicodeTestCase(TestCase):
3315
def test_type_error(self):
3416
with raises(TypeError):
3517
to_unicode(True) # type: ignore
36-
37-
38-
class UnicodeToStrTestCase(TestCase):
39-
def test_deprecation(self):
40-
with deprecated_call():
41-
unicode_to_str("")

w3lib/util.py

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,8 @@
11
from __future__ import annotations
22

3-
from warnings import warn
4-
53
from w3lib._types import StrOrBytes
64

75

8-
def str_to_unicode(
9-
text: StrOrBytes, encoding: str | None = None, errors: str = "strict"
10-
) -> str:
11-
warn(
12-
"The w3lib.utils.str_to_unicode function is deprecated and "
13-
"will be removed in a future release.",
14-
DeprecationWarning,
15-
stacklevel=2,
16-
)
17-
if encoding is None:
18-
encoding = "utf-8"
19-
if isinstance(text, bytes):
20-
return text.decode(encoding, errors)
21-
return text
22-
23-
24-
def unicode_to_str(
25-
text: StrOrBytes, encoding: str | None = None, errors: str = "strict"
26-
) -> bytes:
27-
warn(
28-
"The w3lib.utils.unicode_to_str function is deprecated and "
29-
"will be removed in a future release.",
30-
DeprecationWarning,
31-
stacklevel=2,
32-
)
33-
if encoding is None:
34-
encoding = "utf-8"
35-
if isinstance(text, str):
36-
return text.encode(encoding, errors)
37-
return text
38-
39-
406
def to_unicode(
417
text: StrOrBytes, encoding: str | None = None, errors: str = "strict"
428
) -> str:
@@ -67,17 +33,3 @@ def to_bytes(
6733
if encoding is None:
6834
encoding = "utf-8"
6935
return text.encode(encoding, errors)
70-
71-
72-
def to_native_str(
73-
text: StrOrBytes, encoding: str | None = None, errors: str = "strict"
74-
) -> str:
75-
"""Return str representation of `text`"""
76-
warn(
77-
"The w3lib.utils.to_native_str function is deprecated and "
78-
"will be removed in a future release. Please use "
79-
"w3lib.utils.to_unicode instead.",
80-
DeprecationWarning,
81-
stacklevel=2,
82-
)
83-
return to_unicode(text, encoding, errors)

0 commit comments

Comments
 (0)