Comments (5)
@dreamwalker, @mihau: I will glad to hear your opinion on this feature draft because I know that you are the users of graceful.
from graceful.
I found even more simpler solution. Knowing that functions in Python are descriptors we can allow to specify containers both as class (type) objects and custom methods using only one class attribute: container
. The BaseParam
implementation for that feature would be as follows:
class BaseParam():
container = list
...
If someone wants to have more complex behaviour he can still implement it as a method. That way we get rid of additional class attribute and extra method call for default behaviour.
I was thinking also about adding additional container
keyword argument to BaseParam.__init__
that would allow us to override default container type without the need of subclassing.
Anyone want's to comment on that? @mihau? @tomislater?
from graceful.
Hmm, looks right for me. If someone wants to get more values (not list), he/she can create a function for this (container).
I have another idea. What if we would have value
and values
methods?
Then, if someone passes param many=True
, he has to implement values
method.
For example:
class BaseParam:
def value(self, raw_value):
raise NotImplementedError
def values(self, values):
# raw_values is a list
raise NotImplementedError
class MyParam(BaseParam):
def value(self, raw_value):
return my_magic_function(raw_value)
def values(self, values):
return my_magic_function_for_list(values)
I understand that with this approach, we will have to change the logic in BaseResource.require_params
method concerning getting params.
from graceful.
It seems interesting but I don't know if I get the whole point of this idea. Does values
is supposed to:
- get the list of deserialised values (results of calling
value()
for each one of them)? - get list of raw strings from query string params via request
req.get_param_as_list()
?
If this is (1.) then I think that this is almost the same solution as the proposed with container
but named differently.
If it is (2.) then I think that right now there is very limited gain from such splitting of implementation. I worry that this would make easier for users to take bad design decisions about how their params work. Generally param instances are used to describe parsing/deserialization of single query string parameter and such behaviour should not change with custom many
setting.
Anyway, I do not say definitive no to any of these options. I think we should keep such idea in mind and revisit it later in future if someone finds really practical use case for that.
from graceful.
Yeah, I have meant the first point. I have thought about the second approach (raw values), but it could be difficult to understand.
from graceful.
Related Issues (20)
- Consider getting rid of default param value in "raw" or at least deserialising it only once HOT 3
- Problem: incompatibility with falcon hooks
- Problem: No easy way to create custom per-request context HOT 1
- Add docs section about mixins
- Add missing "version added" and "version changed" specifiers for all previous features and releases
- librelist doesnt seem to work HOT 1
- Rewrite tests in test_generic to pytest-style HOT 1
- 405 when using PUT method HOT 1
- Field validation error uses field source names instead of representation names.
- Writable *-sourced fields break object validation on POST/PUT/PATCH HOT 2
- Support for star-like writable fields HOT 1
- Add "write_only" fields
- Improperly handled fields with many=True
- Better validation error representation.
- Mark all keyword arguments in BaseField as keyword only
- Auth: allow to set detailed authorization requirements for specific HTTP methods
- Revisit terminology and class names.
- Support for serializer's method fields.
- A StringField's value become "None" instead of None when client submit it as null. HOT 5
- Support for OpenApi Generator's graceful generator? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graceful.