mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Modify regex with lookahead in it in argparse
This commit is contained in:
1 parent
dab0a84e83
commit
7a74ca2c9a
1 file changed
+10
-5
+10
-5
@@ -328,14 +328,19 @@ class HelpFormatter(object):
|
||||
|
||||
# break usage into wrappable parts
|
||||
part_regexp = (
|
||||
r'\(.*?\)+(?=\s|$)|'
|
||||
r'\[.*?\]+(?=\s|$)|'
|
||||
r'\S+'
|
||||
r'(\(.*?\)+|\[.*?\]+|\S+)(?:\s|$)'
|
||||
)
|
||||
# FIXME: use regex below once we're compatible with sre
|
||||
# part_regexp = (
|
||||
# r'\(.*?\)+(?=\s|$)|'
|
||||
# r'\[.*?\]+(?=\s|$)|'
|
||||
# r'\S+'
|
||||
# )
|
||||
opt_usage = format(optionals, groups)
|
||||
pos_usage = format(positionals, groups)
|
||||
opt_parts = _re.findall(part_regexp, opt_usage)
|
||||
pos_parts = _re.findall(part_regexp, pos_usage)
|
||||
opt_parts = list(map(lambda t: t[0], _re.findall(part_regexp, opt_usage)))
|
||||
pos_parts = list(map(lambda t: t[0], _re.findall(part_regexp, pos_usage)))
|
||||
print(opt_parts)
|
||||
assert ' '.join(opt_parts) == opt_usage
|
||||
assert ' '.join(pos_parts) == pos_usage
|
||||
|
||||
|
||||
Reference in new issue
Block a user