docopt fails with docopt.DocoptLanguageError: unmatched '['
<p>Why does this code fail with the following exception?</p>

<pre><code>"""my_program - for doing awesome stuff

Usage: my_program [--foo]

Options:
    --foo - this will do foo
"""

import docopt
args = docopt.docopt(doc=__doc__)
</code></pre>

<p>Exception:</p>

<pre><code>Traceback (most recent call last):
  File "/tmp/post.py", line 10, in &lt;module&gt;
    args = docopt.docopt(doc=__doc__)
  File "/Users/rbednark/.virtualenvs/docopt-python2/lib/python3.5/site-packages/docopt.py", line 560, in docopt
    pattern = parse_pattern(formal_usage(DocoptExit.usage), options)
  File "/Users/rbednark/.virtualenvs/docopt-python2/lib/python3.5/site-packages/docopt.py", line 373, in parse_pattern
    result = parse_expr(tokens, options)
  File "/Users/rbednark/.virtualenvs/docopt-python2/lib/python3.5/site-packages/docopt.py", line 381, in parse_expr
    seq = parse_seq(tokens, options)
  File "/Users/rbednark/.virtualenvs/docopt-python2/lib/python3.5/site-packages/docopt.py", line 396, in parse_seq
    atom = parse_atom(tokens, options)
  File "/Users/rbednark/.virtualenvs/docopt-python2/lib/python3.5/site-packages/docopt.py", line 413, in parse_atom
    result = pattern(*parse_expr(tokens, options))
  File "/Users/rbednark/.virtualenvs/docopt-python2/lib/python3.5/site-packages/docopt.py", line 381, in parse_expr
    seq = parse_seq(tokens, options)
  File "/Users/rbednark/.virtualenvs/docopt-python2/lib/python3.5/site-packages/docopt.py", line 396, in parse_seq
    atom = parse_atom(tokens, options)
  File "/Users/rbednark/.virtualenvs/docopt-python2/lib/python3.5/site-packages/docopt.py", line 415, in parse_atom
    raise tokens.error("unmatched '%s'" % token)
docopt.DocoptLanguageError: unmatched '['
</code></pre>

<p>docopt version: <code>0.6.2</code><br>
python versions: <code>2.7.10</code>, <code>3.5.1</code></p>

<p>It fails because of only a single space after <code>--foo</code> on this line:</p>

<pre><code>    --foo - this will do foo
</code></pre>

<p>Fix it by adding another space after <code>--foo</code>:</p>

<pre><code>    --foo  - this will do foo
</code></pre>

<p><br/>
<br/>
Per <a href="https://docopt.readthedocs.io/en/latest/#option-descriptions-format" rel="nofollow">the documentation:</a></p>

<blockquote>
  <p>Use two spaces to separate options with their informal description:</p>
</blockquote>

<pre><code>--verbose More text.   # BAD, will be treated as if verbose option had
                       # an argument "More", so use 2 spaces instead
-q        Quit.        # GOOD
-o FILE   Output file. # GOOD
--stdout  Use stdout.  # GOOD, 2 spaces
</code></pre>

<p><br/>
<br/>
Additional reference: <a href="https://github.com/docopt/docopt" rel="nofollow">docopt source code</a></p>

python docopt