Merge lp:~leonardr/lazr.restful/multiversion-rename-params into lp:lazr.restful
| Status: | Merged |
|---|---|
| Approved by: | Gary Poster on 2010-01-20 |
| Approved revision: | not available |
| Merged at revision: | not available |
| Proposed branch: | lp:~leonardr/lazr.restful/multiversion-rename-params |
| Merge into: | lp:lazr.restful |
| Diff against target: |
355 lines (+226/-84) 2 files modified
src/lazr/restful/declarations.py (+19/-4) src/lazr/restful/docs/webservice-declarations.txt (+207/-80) |
| To merge this branch: | bzr merge lp:~leonardr/lazr.restful/multiversion-rename-params |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Gary Poster | 2010-01-20 | Approve on 2010-01-20 | |
|
Review via email:
|
|||
| Leonard Richardson (leonardr) wrote : | # |
- 101. By Leonard Richardson on 2010-01-20
-
Renamed BleedThroughDict to VersionedDict in response to feedback.
| Gary Poster (gary) wrote : | # |
This looks good. I like the simplification.
On IRC I asked how you were going to use this data structure. You said that you would collect the data, then build the top-most version, pop the dict, build the next lower version, pop the dict, and so on. Therefore, this data structure will be very transient, and you don't need an API to access lower versions while the upper versions are still present. That's fine.
At this point, the whole thing could really be accomplished without a new class. Just the ``stack`` list of (name, dict) tuples, and direct calls to deepcopy for a new level in the stack would seem to add very little additional weight in the call sites. I'm tempted to suggest that you go that way, since it would remove code that might have little win, but on balance I'm fine with you seeing how this data structure will work in practice; maybe this class will actually be significantly nicer to work with for your use cases.
For the name, ``VersionedDict`` makes sense to me, particularly with new approach. OTOH, ``BleedThroughD
Gary
- 102. By Leonard Richardson on 2010-01-20
-
Made sure the cache_for directive works in multiversion.
- 103. By Leonard Richardson on 2010-01-20
-
Implemented operation_
removed_ in_version.

This branch continues my progress towards making all the named operation annotations work in a multi-versioned environment. This branch gets @rename_ parameters_ as to work by radically simplifying the BleedThroughDict data structure.
Since BleedThroughDict has only been around for a couple days, I'll explain how it works. It's a stack of dicts that acts like a single dict. It's used to gather annotations in a multi-versioned environment: the 1.0 annotations all go into a dict at the bottom of the stack, the 2.0 annotations go into a dict on top of that, the 3.0 annotations go into a dict on top of _that_, and so on.
Annotations for version n+1 are inherited from n unless redefined for version n. For instance, if the name of the method being published as a named operation is 'foo', but in the definition of version 2.0 there's an @export_ operation_ as("bar" ), then the name of the operation is 'foo' (the default) in 1.0, but 'bar' in 2.0 and 3.0.
My original plan was that each dict would only contain the annotations specific to that version, and inheritance would be implemented by moving down the stack until I found the version that defined the appropriate annotation. In the example above, the stack would look like this:
[(3.0, {}),
(2.0, {'as' : 'bar'}),
(1.0, {}]
This is elegant, but it only works for annotations that add objects to the annotation dict. The @rename_ parameters_ as annotation takes an object already in the dict and modifies its __name__ attribute in place. This means that if you have @rename_ parameters_ as annotations anywhere in your definition, the last one takes precedence, and modifies the name of that parameter for every single version.
So I changedBleedThr oughDict to get the same basic behavior in a much cruder way. When you push a new dict onto the stack, it's initialized with a deep copy of the dict that was originally the top of the stack. In the example above, the stack would look like this:
[(3.0, {'as' : 'bar'}),
(2.0, {'as' : 'bar'}),
(1.0, {}]
Now a 2.0 @rename_ parameters_ as will modify only the copy of the parameter objects found on the 2.0 level of the stack. It won't affect the objects on the 1.0 level. The 3.0 level will inherit the change made on the 2.0 level (thanks to the deep copy), but it it contains its own @rename_ parameters_ as, that declaration won't affect the 2.0 or the 1.0 levels.
The new BleedThroughDict is not nearly as flexible as the old, but we don't need that flexibility. We always define versions in ascending order and we never go back to modify an old version once it's defined.
I'm entertaining ideas about new names for BleedThroughDict, but I think the name is still appropriate (it's just that the bleeding through happens all at once, not whenever you do a lookup).