This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Convert http.HTTPStatus objects to their int equivalent #7188
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2d85b9d
Convert http.HTTPStatus objects to their int equivalent
anoadragon453 61add4a
Add changelog
anoadragon453 6a0a1de
Don't special-case HTTPStatus. Expand comments
anoadragon453 4b36aa4
Clean up changelog and remove extra space
anoadragon453 395feb3
grammar
anoadragon453 9c43ab0
Remove TODO
anoadragon453 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix consistency of HTTP status codes reported in log lines. Instances of `HTTPStatus.*` are replaced with their integer equivalent. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohh gosh, this is gnarly.
so it turns out that HTTPStatus is a subclass of int:
... so the docstring is correct. Indeed everything works correctly except for the access logger, where it does
str(code)
. Twisted doesb"%d" % code
which does the right thing too.Incidentally, the change of
http.client.<code>
fromint
toIntEnum
happened in python 3.5.It feels like there are multiple potential solutions here:
HTTPStatus
reference with<code>.value
(which may be tricky, because there are many different ways of getting hold of an HTTPStatus reference - which is a separate problem; we should be consistent.)HTTPStatus
herecode = int(code)
herecode = "%d" % (self.code,)
in the access logger codeI'm not sure I have strong feelings. I'm slightly uneasy about the last option, which feels like it might be a bit fragile if Twisted ever decides to switch from
b"%d" % code
tostr(code).encode()
or something.Either way I'd suggest expanding the comments to explain that
HTTPStatus
instances areint
s but with magic__str__
methods which mess us up.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the detailed comment! It looks like we're leaning towards option 3, bearing in mind to aim for option 1 in the long term.
I'll go ahead and change the PR to reflect that and update the comments.