-
-
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
API discussion #233
Comments
|
Do you mean |
Under 1, I'm talking about the namespace subobject, as I think you were. Under 3. I'm talking about 3a. Rename Or...? |
|
One thing we mentioned when discussing #230 is that we might want decorators for methods we decide should not have been made public i.e this might be a tool to help us tighten up the API. |
|
Why decorators? Presumably they just wouldn't be public in the |
At some point I will compile a list of proposed changes out of all the various comments on various issues. For now, I'll just pile on some additional things I'd like to consider:
|
Main APICore
instance_params = {p: parameterized.param[p] for p in parameterized.param}
instance_params = parameterized.param.objects(instance=True) # default
class_params = parameterized.param.objects(instance=False)
class_params = {p: type(parameterized).param[p] for p in parameterized.param}
existing_params = parameterized.param.objects(instance='existing')
Other
Serialization.deserialize_value Watch.params_depended_on Misc.script_repr dynamic.get_value_generator Removed.params |
The above list is only a draft, with lots of questions. The basic goal was to see which methods didn't need to be there at all ("Removed"), and which ones could be replaced with general-purpose Pythonic support under the idea that obj.param should act like a Python dictionary of Parameter objects as closely as possible. I.e., can we eliminate special-purpose API by instead trying to make the object act more closely like a dictionary, as much as is practical? Why would it not be practical? Well, under the covers .param it is not simply a dictionary of Parameter objects, because the Parameter object may be on this Parameterized instance, or it may be on the corresponding class, or it may be on some superclass. Plus the value of the Parameter isn't actually stored in the Parameter object, only the Parameterized instance. For iteration without mutation, where the actual Parameter object is stored doesn't matter, but it does matter if iteration changes where the Parameter is stored (as .object currently does by default), and it does matter if the user can modify the Parameter object during iteration (which would have wildly different impacts depending on where that Parameter object is stored, either affecting only this instance or affecting all instances of this class or other classes). The proposal so far is to see if we can approximate normal dictionary-like behavior by providing read-only views of Parameter objects. Can we get rid of such special-purpose iterating methods as |
Just to officially record something I've been saying: I think iterating over named tuples containing snapshots of parameter state would ensure immutability in a way that is obvious (and still practical) for users. Having a way to toggle immutability on Parameters would avoid needing named tuples but I'm not sure this is worth the effort (and if you do this, you would need good error messages explaining why the Parameter has been set to immutable). |
Closing in favor of #543 |
PR #230 gives us an opportunity to clean up the namespace of parameterized objects but it also gives us a chance to tidy up the rest of the API: we can define the API we want for the future on
.param
while retaining backwards compatibility.This issue is intended to start some discussion. Here are some of my own notes:
Notes
pprint
,script_repr
,instance
(for ParameterizedFunctions) and.param
itself of course. There is also a.initialized
attribute that I think should be private. What should be exposed at this level?script_repr
in future at the parameterized level?.params()
sometimes returns a dictionary and sometimes does not has always seemed odd to me.set_default
seems odd as you might want to set other parameter attributes too. Shouldn't there be a more general way to set any parameter attribute?What are your own thoughts on this issue?
The text was updated successfully, but these errors were encountered: