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
Fix: Make error initializers more consistent #1655
Conversation
… has optional representation
Codecov Report
@@ Coverage Diff @@
## master #1655 +/- ##
========================================
Coverage ? 100%
========================================
Files ? 47
Lines ? 3565
Branches ? 545
========================================
Hits ? 3565
Misses ? 0
Partials ? 0
Continue to review full report at Codecov.
|
I've a couple of questions:
|
Yes, I think that would be a Good Thing™. As an aside, we should consider doing this in other places as well so we don't have to worry about a simple reordering of kwargs down the road causing a breaking change. @vytas7 thoughts? |
It would not hurt to normalize the ordering of extra params such that they always follow headers (although it would only be cosmetic if PEP 3102 is used). Regardless, we will need to make sure we have test coverage for things like that overriding any values also set in headers. |
@@ -377,11 +372,9 @@ class HTTPMethodNotAllowed(OptionalRepresentation, HTTPError): | |||
base articles related to this error (default ``None``). | |||
""" | |||
|
|||
def __init__(self, allowed_methods, headers=None, **kwargs): | |||
def __init__(self, allowed_methods, title=None, description=None, headers=None, **kwargs): |
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.
We'll need a breaking change news fragment since people may have been passing headers positionally.
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.
I'll add it to the existing one regarding the NoRepresentation
. Also the kw only change
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.
btw towncrier
does not properly render the misc changelog
I think the current implementation overrides in all of them. I can check if that is the case and check if there are tests for it. Sadly the code coverage does not help in this case |
@@ -0,0 +1,2 @@ | |||
Update to the error classes in ``falcon.errors`` to have ``title`` and |
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.
This needs just a slight rewording to be consistent with other fragments:
The error classes in ``falcon.errors`` were updated to have...
I'm changing to kwonly. There seem to be a lot of changes required, both in code and in documentations. |
I've notices that for the headers the documentation says: But the list case is not handled by all the errors that add something to the headers, like Lines 165 to 170 in c817a42
|
should be almost done other than #1655 (comment) |
I know I'm the one who suggested it, and I've already implemented it, but thinking a bit more about it and also judging by the amount of refactoring that this has required in falcon, I'm not sure if it's worth the trouble. By it I mead that it will probably cause a lot of refactoring on the users who use falcon, without a clear improvement. |
I'd need to check signatures of the existing A quick reaction off the top of my head would be that it indeed sounds like a bit too abrupt breaking change without any compatibility shims or deprecation warnings, even given that 3.0 will be a major release. |
IMO we should at least add a warning section to the relevant docstrings. As for outputting a deprecation warning, I'm inclined to say yes as well, since this raising errors is typically not super performance sensitive, and the extra nudge to the app developer can't hurt. @vytas7 thoughts? |
Agreed re the deprecation warning, not many are going to care or even notice about a line or two in the docs. It is ideal to emit them if possible, and agreed re the performance impact being lesser for exceptions. |
ok, so something like the |
b77821d
to
6969e0c
Compare
Ok I've replaced the kwonly with a warning and a note in the documents. (not sure if it should be a warning) I think it's ready for review |
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.
Just a few minor things and this should be ready to merge!
I've noticed that the changelog needs updating. |
docs/_newsfragments/777.removal.rst
Outdated
@@ -0,0 +1,4 @@ | |||
The class :class:`~.falcon.http_error.NoRepresentation` was removed since | |||
all :class:`~.falcon.HTTPError` have optional representation. | |||
Deprecate the use of positional arguments for the optional kw args of |
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.
Seems like this deprecation could be its own news fragment?
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.
I'm not sure how to name them. They should be 777 since that is the issue, and I think are both removal?
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.
You could make the other one "misc" since it hasn't been removed (as a breaking change) yet, per se. Also, I think it is reasonable to add a few (hyphenated) words of description after the issue number (as has been done with other fragments.
@csojinb @vytas7 thoughts? Related: #1621 (comment)
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.
I've used only the numbers as the names since I though that we wanted to use towncrier to automatically add the link to the issue for every changelog file.
If we don't need to only use the number as the name I'll make a new misc file
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.
Ahh, I see. I just tried that and indeed it drops a (#{number})
reference in there, although it doesn't generate a GH link by default. That is nice, but on the other hand it seems like there should be a way to (1) have towncrier allow multiple entries for the same issue and (2) to better support items that don't have an associated issue, perhaps by simply not appending the (name-of-news-fragment)
. Perhaps we need a post-processing script?
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.
There is a configuration parameter for towncrier to make it apply the gh link. We were trying it in gitter with @vytas7
I can just change the name for now, and then the names of the newsitems will be changed after the configuration for towncrier is figured out
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.
the config was issue_format = "https://github.com/falconry/falcon/issues/{issue}"
Nice catch! I think we are all trying to get used to making news fragments part of the PRs. |
Summary of Changes
Normalized the interface of the http errors with common title and description kwargs.
Compared to the issue I've left the
headers
kw as is, since it's used in all errorsRelated Issues
Fixes: #777
Pull Request Checklist
This is just a reminder about the most common mistakes. Please make sure that you tick all appropriate boxes. But please read our contribution guide at least once; it will save you a few review cycles!
If an item doesn't apply to your pull request, check it anyway to make it apparent that there's nothing to do.
docs/
.docs/
.versionadded
,versionchanged
, ordeprecated
directives.docs/_newsfragments/
. (Runtowncrier --draft
to ensure it renders correctly.)If you have any questions to any of the points above, just submit and ask! This checklist is here to help you, not to deter you from contributing!
PR template inspired by the attrs project.