-
Notifications
You must be signed in to change notification settings - Fork 13
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
Enable better composition model #238
Comments
not sure the colocation pattern actually gives you more expressiveness. |
It's more like keeping things together. Separately handling "soft delete" or "entity create" mixins on models and views in different modules is annoying and seems potentially error-prone. |
Seems like this could be done in a way that doesn't break backwards compat as well. |
Doesn't solve the multi-inheritance issue, but you could get most of the colocation benefits by organizing modules by resource. # widgets.py
class WidgetAuthorization(..., Auth):
class WidgetSchema(..., TableSchema):
class Meta:
table = Widget.__table__
class BaseWidgetView(... BaseView):
class WidgetListView(BaseWidgetView):
class WidgetView(BaseWidgetView):
api.add_resource('/api/widgets/', WidgetListView, WidgetView) Update: Removed the model; models aren't 1:1 with resources, so probably still belong in a separate models.py |
we should definitely try that to at least see how it feels. for big projects I think it might be better |
Yusssssss |
I'll write up a quick decision doc in notion and get yall to weigh in |
The issue FWIW is that cross-module imports in Python suck because exports are values, not bindings. So there will be some awkwardness there. |
For larger APIs, the composition model in Flask-RESTy gets a bit messy. We often end up with multiple parallel complex inheritance trees in separate
auth
,schemas
, andviews
modules, and a single view may compose in a half-dozen or more base classes and mixins. This is not ideal for understandability; the MRO gets complex enough that it's often not easy to figure out which method overrides which, or whatsuper
calls do.For auth, many of these problems will be solved by #236. Outside of auth, though, we need to brainstorm further on how to make these work. One option is to move toward embedding class definitions for functionality. This would then allow patterns like:
Also, to limit the number of base classes in views, we could factor out classes to handle specific actions. For example, instead of something like:
This could also enable patterns like:
i.e. allow better co-location of mixin-type behavior across models and views.
This likely will require some version of #237.
The text was updated successfully, but these errors were encountered: