Skip to content

Commit

Permalink
chore(response): remove previously deprecated Response.add_link()
Browse files Browse the repository at this point in the history
  • Loading branch information
vytas7 committed Sep 21, 2024
1 parent 07c9920 commit 9184c19
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 33 deletions.
3 changes: 3 additions & 0 deletions docs/_newsfragments/1853.breakingchange.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ removed:
:class:`~falcon.routing.CompiledRouter`. In a pinch, you can simply copy its
implementation from the Falcon 3.x source tree into your application.

* The deprecated ``Response.add_link()`` method was removed; please use
:meth:`Response.append_link <falcon.Response.append_link>` instead.

* The deprecated ``has_representation()`` method for :class:`~falcon.HTTPError`
was removed, along with the ``NoRepresentation`` and
``OptionalRepresentation`` classes.
Expand Down
2 changes: 1 addition & 1 deletion docs/_newsfragments/2253.misc.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
The :ref:`utility functions <util>` ``create_task()`` and
``get_running_loop()`` are now deprecated in favor of their standard library
counterparts, :func:`asyncio.create_task` and `:func:`asyncio.get_running_loop`.
counterparts, :func:`asyncio.create_task` and :func:`asyncio.get_running_loop`.
25 changes: 6 additions & 19 deletions falcon/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
from falcon.util import http_status_to_code
from falcon.util import structures
from falcon.util.deprecation import AttributeRemovedError
from falcon.util.deprecation import deprecated
from falcon.util.uri import encode_check_escaped as uri_encode
from falcon.util.uri import encode_value_check_escaped as uri_encode_value

Expand Down Expand Up @@ -210,20 +209,6 @@ def status_code(self) -> int:
def status_code(self, value: int) -> None:
self.status = value

@property
def body(self) -> NoReturn:
raise AttributeRemovedError(
'The body attribute is no longer supported. '
'Please use the text attribute instead.'
)

@body.setter
def body(self, value: Any) -> NoReturn:
raise AttributeRemovedError(
'The body attribute is no longer supported. '
'Please use the text attribute instead.'
)

@property
def data(self) -> Optional[bytes]:
"""Byte string representing response content.
Expand Down Expand Up @@ -983,10 +968,12 @@ def append_link(
else:
_headers['link'] = value

# NOTE(kgriffs): Alias deprecated as of 3.0
add_link = deprecated('Please use append_link() instead.', method_name='add_link')(
append_link
)
@property
def add_link(self) -> NoReturn:
raise AttributeRemovedError(

Check warning on line 973 in falcon/response.py

View check run for this annotation

Codecov / codecov/patch

falcon/response.py#L973

Added line #L973 was not covered by tests
'The add_link() method is no longer supported. '
'Please use append_link() instead.'
)

cache_control: Union[str, Iterable[str], None] = header_property(
'Cache-Control',
Expand Down
5 changes: 4 additions & 1 deletion falcon/util/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ class TimezoneGMT(datetime.tzinfo):

GMT_ZERO = datetime.timedelta(hours=0)

@deprecated('TimezoneGMT is deprecated, use datetime.timezone.utc instead')
@deprecated(
'TimezoneGMT is deprecated, use datetime.timezone.utc instead. '
'(TimezoneGMT will be removed in Falcon 5.0.)'
)
def __init__(self) -> None:
super().__init__()

Expand Down
6 changes: 3 additions & 3 deletions tests/test_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,12 +867,12 @@ def test_append_link_multiple(self, client):
uri = 'ab\u00e7'

resource = LinkHeaderResource()
resource.add_link('/things/2842', 'next')
resource.append_link('/things/2842', 'next')
resource.append_link('http://\u00e7runchy/bacon', 'contents')
resource.append_link(uri, 'http://example.com/ext-type')
resource.add_link(uri, 'http://example.com/\u00e7runchy')
resource.append_link(uri, 'http://example.com/\u00e7runchy')
resource.append_link(uri, 'https://example.com/too-\u00e7runchy')
resource.add_link('/alt-thing', 'alternate http://example.com/\u00e7runchy')
resource.append_link('/alt-thing', 'alternate http://example.com/\u00e7runchy')

self._check_link_header(client, resource, expected_value)

Expand Down
8 changes: 8 additions & 0 deletions tests/test_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from falcon import MEDIA_TEXT
from falcon import ResponseOptions
from falcon.util.deprecation import AttributeRemovedError


@pytest.fixture()
Expand Down Expand Up @@ -39,6 +40,13 @@ def test_response_get_headers(resp):
assert 'set-cookie' not in headers


def test_add_link_removed(resp):
# NOTE(kgriffs): Ensure AttributeRemovedError inherits from AttributeError
for exc_type in (AttributeError, AttributeRemovedError):
with pytest.raises(exc_type):
resp.add_link('/things/1337', 'next')


def test_response_attempt_to_set_read_only_headers(resp):
resp.append_header('x-things1', 'thing-1')
resp.append_header('x-things2', 'thing-2')
Expand Down
9 changes: 0 additions & 9 deletions tests/test_response_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import falcon
from falcon import testing
from falcon.util.deprecation import AttributeRemovedError


@pytest.fixture
Expand All @@ -14,20 +13,12 @@ def test_append_body(resp):
text = 'Hello beautiful world! '
resp.text = ''

with pytest.raises(AttributeRemovedError):
resp.body = 'x'

for token in text.split():
resp.text += token
resp.text += ' '

assert resp.text == text

# NOTE(kgriffs): Ensure AttributeRemovedError inherits from AttributeError
for ErrorType in (AttributeError, AttributeRemovedError):
with pytest.raises(ErrorType):
resp.body


def test_response_repr(resp):
_repr = '<%s: %s>' % (resp.__class__.__name__, resp.status)
Expand Down

0 comments on commit 9184c19

Please sign in to comment.