Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated functions. #235

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 2 additions & 26 deletions tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
from unittest import TestCase

from pytest import deprecated_call, raises
from pytest import raises

from w3lib.util import (
str_to_unicode,
to_bytes,
to_native_str,
to_unicode,
unicode_to_str,
)


class StrToUnicodeTestCase(TestCase):
def test_deprecation(self):
with deprecated_call():
str_to_unicode("")
from w3lib.util import to_bytes, to_unicode


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


class ToNativeStrTestCase(TestCase):
def test_deprecation(self):
with deprecated_call():
to_native_str("")


class ToUnicodeTestCase(TestCase):
def test_type_error(self):
with raises(TypeError):
to_unicode(True) # type: ignore


class UnicodeToStrTestCase(TestCase):
def test_deprecation(self):
with deprecated_call():
unicode_to_str("")
48 changes: 0 additions & 48 deletions w3lib/util.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,8 @@
from __future__ import annotations

from warnings import warn

from w3lib._types import StrOrBytes


def str_to_unicode(
text: StrOrBytes, encoding: str | None = None, errors: str = "strict"
) -> str:
warn(
"The w3lib.utils.str_to_unicode function is deprecated and "
"will be removed in a future release.",
DeprecationWarning,
stacklevel=2,
)
if encoding is None:
encoding = "utf-8"
if isinstance(text, bytes):
return text.decode(encoding, errors)
return text


def unicode_to_str(
text: StrOrBytes, encoding: str | None = None, errors: str = "strict"
) -> bytes:
warn(
"The w3lib.utils.unicode_to_str function is deprecated and "
"will be removed in a future release.",
DeprecationWarning,
stacklevel=2,
)
if encoding is None:
encoding = "utf-8"
if isinstance(text, str):
return text.encode(encoding, errors)
return text


def to_unicode(
text: StrOrBytes, encoding: str | None = None, errors: str = "strict"
) -> str:
Expand Down Expand Up @@ -67,17 +33,3 @@ def to_bytes(
if encoding is None:
encoding = "utf-8"
return text.encode(encoding, errors)


def to_native_str(
text: StrOrBytes, encoding: str | None = None, errors: str = "strict"
) -> str:
"""Return str representation of `text`"""
warn(
"The w3lib.utils.to_native_str function is deprecated and "
"will be removed in a future release. Please use "
"w3lib.utils.to_unicode instead.",
DeprecationWarning,
stacklevel=2,
)
return to_unicode(text, encoding, errors)
Loading