paul j3 <ajipa...@gmail.com> added the comment:

I haven't seen anyone try to use \n in a metavar before, but other special 
characters like [] and () produce this assertion error.  At this point the code 
is trying split the usage into 2 or more lines, because it's too long for one.  
It creates a usage for optionals and positionals separately.

In a clumsy way, it formats the whole usage string, and tries to split it into 
pieces so it can decide to split long lines.  The 'assert' is used to make sure 
it has split the line into meaningful blocks.  It splits with

    r'\(.*?\)+|\[.*?\]+|\S+'

basically white space (including nl) and [] and () which are used to mark 
optional arguments and groups.  So including any of these characters in text 
via metavar will screwup this split.

We could try to refine this splitting expression, but that feels like a never 
ending task as users become more inventive.

I suggested a major rewrite of this section, one that keeps the pieces a list, 
and joins them after deciding how many can fit on a line.

No one has, to my knowledge, come up with a comprehensive list of characters 
that will cause problems here.

argparse does provide a backup - a user provided usage string.  That's not as 
nice as a automatically generated one, but if you have to have something 
special, that's the way to go.  In the long run there's only so much that 
general purpose parser can do to accommodate special needs.

----------
nosy: +paul.j3

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32867>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to