Merge pull request #354 from JordanP/use_isinstance
Use ``isinstance(`` instead of ``issubclass(type(``
This commit is contained in:
commit
c81c92967c
|
@ -23,7 +23,7 @@ class CustomHandler(Handler):
|
||||||
# and can do anything with it (log, send to external service, etc)
|
# and can do anything with it (log, send to external service, etc)
|
||||||
|
|
||||||
# Some exceptions are trivial and built into Sanic (404s, etc)
|
# Some exceptions are trivial and built into Sanic (404s, etc)
|
||||||
if not issubclass(type(exception), SanicException):
|
if not isinstance(exception, SanicException):
|
||||||
print(exception)
|
print(exception)
|
||||||
|
|
||||||
# Then, we must finish handling the exception by returning
|
# Then, we must finish handling the exception by returning
|
||||||
|
|
|
@ -188,7 +188,7 @@ class Handler:
|
||||||
|
|
||||||
def default(self, request, exception):
|
def default(self, request, exception):
|
||||||
log.error(format_exc())
|
log.error(format_exc())
|
||||||
if issubclass(type(exception), SanicException):
|
if isinstance(exception, SanicException):
|
||||||
return text(
|
return text(
|
||||||
'Error: {}'.format(exception),
|
'Error: {}'.format(exception),
|
||||||
status=getattr(exception, 'status_code', 500))
|
status=getattr(exception, 'status_code', 500))
|
||||||
|
|
|
@ -51,7 +51,7 @@ def test_middleware_response():
|
||||||
assert response.text == 'OK'
|
assert response.text == 'OK'
|
||||||
assert type(results[0]) is Request
|
assert type(results[0]) is Request
|
||||||
assert type(results[1]) is Request
|
assert type(results[1]) is Request
|
||||||
assert issubclass(type(results[2]), HTTPResponse)
|
assert isinstance(results[2], HTTPResponse)
|
||||||
|
|
||||||
|
|
||||||
def test_middleware_override_request():
|
def test_middleware_override_request():
|
||||||
|
|
|
@ -152,7 +152,7 @@ def test_with_middleware_response():
|
||||||
assert response.text == 'I am get method'
|
assert response.text == 'I am get method'
|
||||||
assert type(results[0]) is Request
|
assert type(results[0]) is Request
|
||||||
assert type(results[1]) is Request
|
assert type(results[1]) is Request
|
||||||
assert issubclass(type(results[2]), HTTPResponse)
|
assert isinstance(results[2], HTTPResponse)
|
||||||
|
|
||||||
|
|
||||||
def test_with_custom_class_methods():
|
def test_with_custom_class_methods():
|
||||||
|
|
Loading…
Reference in New Issue
Block a user