docopt/docopt — pull request #156 by jaredgrubb (2013-10-23 04:26:56+00:00)
Title: Some minor changes to help aid in porting; mostly non-functional changes

While preparing the C++ port, I had a few suggestions to help ease porting for other languages:
* I moved the "fix" functions in Pattern to the BranchPattern subclass. These functions do not apply to leaf nodes, and moving them down helps makes Pattern's interface clearer. This also lets us remove the "hasattr('children')" check.
* Add some __init__ up-calls that were missing (some non-functional, but still should be included for correctness, in my opinion).
* Added some extra comments.
* Changed "Tokens" to not inherit from "list". The only thing that Token really needed was to be iterable, and that can be accomplished via __iter__. I'm always hesitant to subclass fundamental types, as it is to easy for others to accidentally strip it later.

I considered changing the "transform" function and remove the Either/Required parts at the end. The only caller of this function unwraps the Either and the Required and just operates on the children. In the C++ port, I made this function take a list of patterns and return a list-of-list-of-patterns, and avoided wrapping either in Either/Required classes. I'm not sure if this is helpful or not, so I didnt include it -- but I thought I'd bring it up.

I understand this patch may be controversial, but hopefully it's helpful (or at least some parts).