falconry / falcon

The no-magic web data plane API and microservices framework for Python developers, with a focus on reliability, correctness, and performance at scale.
https://falcon.readthedocs.io/en/stable/
Apache License 2.0
9.51k stars 937 forks source link

feat: status_code attribute for Response, HTTPError, HTTPStatus #2108

Closed kgriffs closed 2 years ago

kgriffs commented 2 years ago

This patch adds a status_code attribute (property) to the Response, HTTPError, and HTTPStatus classes to afford introspection by middleware and error handlers.

codecov[bot] commented 2 years ago

Codecov Report

Merging #2108 (d9698c3) into master (5d1b1cb) will not change coverage. The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master     #2108   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           62        62           
  Lines         6746      6759   +13     
  Branches      1255      1255           
=========================================
+ Hits          6746      6759   +13     
Impacted Files Coverage Δ
falcon/asgi/response.py 100.00% <ø> (ø)
falcon/asgi/app.py 100.00% <100.00%> (ø)
falcon/http_error.py 100.00% <100.00%> (ø)
falcon/http_status.py 100.00% <100.00%> (ø)
falcon/response.py 100.00% <100.00%> (ø)
falcon/util/misc.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

kgriffs commented 2 years ago

considering typing, I think it would be nicer if status had a narrower type, but there has always been the possibility of setting multiple types so nothing new here.

for the rest it seems ok

Ideally we would have added status_code before this and left status alone, but I'd like to just keep the consistency for now and avoid breaking changes; we can consider changing things up in the next major release.

CaselIT commented 2 years ago

The main issue I see is that necessarly status has type int | str | HTTPStatus, but usually only one of these is used in application.

But at worst we can add a status_str that does the same as status_code but always returns the string