Make the doc
argument optional; use the docstring for the caller's module by default
#318
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The most common way to use docopt is to write a module docstring and to pass it to
docopt.docopt()
using the special__doc__
global variable:This pull request makes this the default behavior. In other words, the code below would be equivalent to the code above:
There are two advantages to having this be the default behavior. First, users who aren't experienced enough to know that docstrings are accessible to their scripts via
__doc__
won't need to worry about that detail anymore. Second, this saves some typing in the most common case. I type the docopt header in almost every script I write, so shortening it by ~20% would be nice.It's worth noting that this feature uses the
inspect
module to interrogate the caller's stack frame and global namespace. This is somewhat magical, but I don't think it's any more magical (or different in philosophy) than usingsys.argv
by default.New tests and updated documentation are included in the pull request.