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

chore(http_error): remove deprecated code #1900

Merged
merged 6 commits into from
May 21, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
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