Skip to content

Commit

Permalink
chore(http_error): remove deprecated code (#1900)
Browse files Browse the repository at this point in the history
* remove deprecated code from http_error module

* doc(changes): add news fragment for removal of deprecated codehttp_error

* docs(newsfragments): fix a misspelling NoRespresentation (sic) ==> NoRepresentation

Co-authored-by: Vytautas Liuolia <vytautas.liuolia@gmail.com>
Co-authored-by: Kurt Griffiths <mail@kgriffs.com>
  • Loading branch information
3 people authored May 21, 2022
1 parent a9ea4a9 commit fe5f94b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 110 deletions.
3 changes: 3 additions & 0 deletions docs/_newsfragments/1853.breakingchange.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The deprecated ``has_representation()`` method for :class:`~falcon.HTTPError` was
removed, along with the ``NoRepresentation`` and ``OptionalRepresentation``
classes.
77 changes: 0 additions & 77 deletions falcon/http_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

from falcon.constants import MEDIA_JSON
from falcon.util import uri
from falcon.util.deprecation import deprecated
from falcon.util.deprecation import deprecated_args


Expand Down Expand Up @@ -136,14 +135,6 @@ def __repr__(self):

__str__ = __repr__

@property # type: ignore
@deprecated(
'has_representation is deprecated and is currently unused by falcon',
is_property=True,
)
def has_representation(self):
return True

def to_dict(self, obj_type=dict):
"""Return a basic dictionary representing the error.
Expand Down Expand Up @@ -225,71 +216,3 @@ def to_xml(self):
# NOTE: initialized in falcon.media.json, that is always imported since Request/Respose
# are imported by falcon init.
_DEFAULT_JSON_HANDLER = None


class NoRepresentation:
"""Mixin for ``HTTPError`` child classes that have no representation.
This class can be mixed in when inheriting from ``HTTPError``, in order
to override the `has_representation` property such that it always
returns ``False``. This, in turn, will cause Falcon to return an empty
response body to the client.
You can use this mixin when defining errors that either should not have
a body (as dictated by HTTP standards or common practice), or in the
case that a detailed error response may leak information to an attacker.
Note:
This mixin class must appear before ``HTTPError`` in the base class
list when defining the child; otherwise, it will not override the
`has_representation` property as expected.
Warning:
As of Falcon 3.0, this mixin class is no longer used since all Falcon
errors have a representation. This class is considered deprecated and
will be removed in a future release.
"""

@property # type: ignore
@deprecated(
'has_representation is deprecated and is currently unused by falcon. '
'The class NoRepresentation is deprecated and will be removed in a '
'future release',
is_property=True,
)
def has_representation(self):
return False


class OptionalRepresentation:
"""Mixin for ``HTTPError`` child classes that may have a representation.
This class can be mixed in when inheriting from ``HTTPError`` in order
to override the `has_representation` property, such that it will
return ``False`` when the error instance has no description
(i.e., the `description` kwarg was not set).
You can use this mixin when defining errors that do not include
a body in the HTTP response by default, serializing details only when
the web developer provides a description of the error.
Note:
This mixin class must appear before ``HTTPError`` in the base class
list when defining the child; otherwise, it will not override the
`has_representation` property as expected.
Warning:
As of Falcon 3.0, this mixin class is no longer used since all Falcon
errors have a representation. This class is considered deprecated and
will be removed in a future release.
"""

@property # type: ignore
@deprecated(
'has_representation is deprecated and is currently unused by falcon. '
'The class OptionalRepresentation is deprecated and will be removed '
'in a future release',
is_property=True,
)
def has_representation(self):
return self.description is not None
33 changes: 0 additions & 33 deletions tests/test_httperror.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import yaml

import falcon
from falcon.http_error import NoRepresentation, OptionalRepresentation
import falcon.testing as testing
from falcon.util.deprecation import DeprecatedWarning

Expand Down Expand Up @@ -280,10 +279,6 @@ def test_base_class(self, client):
assert response.status == headers['X-Error-Status']
assert response.json == expected_body

def test_has_representation(self):
with pytest.warns(DeprecatedWarning, match='has_representation is deprecated'):
assert falcon.HTTPError(falcon.HTTP_701).has_representation is True

def test_no_description_json(self, client):
response = client.simulate_patch('/fail')
assert response.status == falcon.HTTP_400
Expand Down Expand Up @@ -925,31 +920,3 @@ def test_kw_only():
# falcon.HTTPError(falcon.HTTP_BAD_REQUEST, 'foo', 'bar')
with pytest.warns(DeprecatedWarning, match='positional args are deprecated'):
falcon.HTTPError(falcon.HTTP_BAD_REQUEST, 'foo', 'bar')


def test_NoRepresentation():
with pytest.warns(
DeprecatedWarning,
match='has_representation is deprecated.*The class NoRepresentation',
):
assert NoRepresentation().has_representation is False


class TestOptionalRepresentation:
def test_OptionalRepresentation_false(self):
with pytest.warns(
DeprecatedWarning,
match='has_representation is deprecated.*The class OptionalRepresentation',
):
or_ = OptionalRepresentation()
or_.description = None
assert or_.has_representation is False

def test_OptionalRepresentation_true(self):
with pytest.warns(
DeprecatedWarning,
match='has_representation is deprecated.*The class OptionalRepresentation',
):
or_ = OptionalRepresentation()
or_.description = 'foo'
assert or_.has_representation is True

0 comments on commit fe5f94b

Please sign in to comment.