-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
Additional features for @param.output #140
Comments
It's interesting to think about how this relates to Python 3 type hinting, but there they seem to focus only on static declarations, not run-time checking as we propose here, so it doesn't seem like we could make use of what's currently available. Plus of course we want to support both 2 and 3... |
1 - Agreed. Docstrings are a key part of what param offers ! Not saying we should be a slave to any other convention! It might still be good to look at to see if there are any good ideas worth adopting... |
3 - should probably have been split into two bullet points:, 3a how composite types should be specified and 3b multiple possible return types can be specified. For 3b, we agree that None is sufficient as the only initially supported variant return type. For 3a we have no answer yet, and we can probably postpone addressing it at first (though it strongly affects bullet point 2). 5 - It seems like there are at least two different use cases for "self" -- one is just when one wants to supply a Parameterized object to another object, in which case the specific type of self is fine (as that can always be compared against some more general type that's the actual requirement of the downstream consumer). Here it sounds like you mean supporting a method that returns self, and you want to declare what type is returned by that method? I can't see how we'd have access to that information from a decorator on a superclass's method, but maybe that's possible. BTW, if you're adding a decorator for specifying the output type and docstring for a method call, you might also want to add one specifying the argument types and docstrings for the method call (potentially even the constructor?). |
I agree with what you said for 3 i.e postponing how composite types are specified and only supporting
This was the case I had in mind and I wasn't considering implementation details. It is a feature I would like and I don't know if it is possible!
That could also be a useful feature but I think an additional such decorator would be classified as a new issue/separate feature request. |
I agree that's a separate feature, but one that would probably become trivial once this one is implemented. |
Param now has an |
One of the major goals of param is to apply type validation and it does this well for Python literals. When it comes to callable objects, param is very lenient by assuming that the return value of the callable is of the right type. This is why you can use a
imagen.PatternGenerator
as the value of aparam.Number
for instance, even though the output of thePatternGenerator
is incompatible.For
param.Number
the line responsible for this hole in validation is here asself._check_value
is skipped for callables. This situation could be improved by introducing support for a type annotation declaring the expected type of a method.The API is still being decided, but perhaps we could have something like:
Then you could query for the decorated types:
API questions
@param.output
have? Setting the type as a mandatory first argument seems to make sense (every method has a single return value).str
,np.ndarray
) or parametersparam.String, param.Integer
or both?(int, str)
or maybe multiple possible types?(int, str) | None
?These issues are worth thinking about even if the initial approach starts simple. It might also be worth looking at the type annotation syntax standardised in Python 3....
The text was updated successfully, but these errors were encountered: