-
Notifications
You must be signed in to change notification settings - Fork 886
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
Expose response class #1499
Expose response class #1499
Conversation
For clarity, |
Other than that, LGTM. |
registry = Registry() | ||
|
||
request = MyRequest({}) | ||
factory = _get_response_factory(registry, request) |
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.
registry
undefined, breaks Travis.
@tseaver Sorry about that, made a quick change and didn't test it locally. Its fixed now :) |
This looks great. One small gripe. It looks like
I'd opt for something like |
I've thought more about this and I retract my complaints. I was trying to make it such that if a user wanted to override the response factory they could do so via setting I think the only thing left in this PR is to add a |
@mmerickel I've made the |
LGTM |
Before we make this API public I want to raise one concern. I think the |
If we require the argument, some uses will drop it on the floor, but if we don't, then some uses might be left hanging. For instance, right now, our I think if we do make it required then we should override the default |
I think that sending the class as the factory is an anti-pattern and it'd be better to just |
@mmerickel |
We added |
If we are super concerned about breaking someone using the current private API then we could add another interface for the new public api but I don't think it's necessary. |
@mmerickel Only thing I'm worried about at that point is the |
@mmerickel 32cb805 turns the response factory into a factory that takes a request and drops support for using |
I like the idea of being able to pass the request to the Could you also add an entry to |
@sontek yes I think we should ignore the fact that |
This PR looks great. Final request is to please either a) remove |
@mmerickel I prefer having it because we can change the implementation in one place, I'll make the move though |
Tank you SO MUCH |
default=Response) | ||
return response_factory() | ||
response_factory = _get_response_factory(self.registry) | ||
return response_factory(self) |
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.
@mmerickel This is backward incompatibility (not mentioned in CHANGES.txt for 1.6 ), because response_factory can not be Response class now.
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 impl of _get_response_factory
is identical to this code and defaults to Response
if the user has not registered their own factory. I see no incompatibility here.
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 think maybe what you are referring to is changing the factory to accept the request
object. Unfortunately IResponseFactory
was a private API prior to 1.6 so we do not need to document those internal changes.
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.
Yes, I used in 1.5 IResponseFactory in order to set custom Response class. It seems there was no other way.
How could I know that is private and how should I set custom Response class in 1.5?
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.
Custom responses classes were not officially supported in 1.5. Pyramid documents all public APIs in the API section of the documentation.
Note the difference from http://docs.pylonsproject.org/projects/pyramid/en/1.5-branch/api/interfaces.html to http://docs.pylonsproject.org/projects/pyramid/en/1.6-branch/api/interfaces.html with regards to IResponseFactory
.
This is a small clean-up to utilize the
ResponseClass
that is already available on the Request object. This allows developers to define their own request factory with a new response class and have it used everywhere.This is an attempt to help with #1256
As was suggested in the ticket, it might make more sense to just create a
set_response_factory
API and aresponse_factory
kwarg of the configurator, but since the ResponseClass is already there it doesn't hurt to utilize it. I can't think of a time you would want to create a response when you don't have a request which is why I opted to take this route instead.