2020
2121def map_nested_definitions (nested_content ):
2222 if nested_content is None :
23- raise Exception ('Nested content should be iterable, not null' )
23+ msg = 'Nested content should be iterable, not null'
24+ raise Exception (msg )
2425 # build definition dictionary
2526 definitions = {}
2627 for item in nested_content :
@@ -37,24 +38,24 @@ def map_nested_definitions(nested_content):
3738 ci = subitem [idx ]
3839 if len (ci .children ) > 0 :
3940 classifier = ci .children [0 ].astext ()
40- if classifier is not None and classifier not in (
41+ if classifier is not None and classifier not in {
4142 '@replace' ,
4243 '@before' ,
4344 '@after' ,
4445 '@skip' ,
45- ):
46- raise Exception (f'Unknown classifier: { classifier } ' )
46+ }:
47+ msg = f'Unknown classifier: { classifier } '
48+ raise Exception (msg )
4749 idx = subitem .first_child_matching_class (nodes .term )
4850 if idx is not None :
4951 term = subitem [idx ]
5052 if len (term .children ) > 0 :
5153 term = term .children [0 ].astext ()
5254 idx = subitem .first_child_matching_class (nodes .definition )
5355 if idx is not None :
54- subcontent = []
55- for _ in subitem [idx ]:
56- if isinstance (_ , nodes .definition_list ):
57- subcontent .append (_ )
56+ subcontent = [
57+ _ for _ in subitem [idx ] if isinstance (_ , nodes .definition_list )
58+ ]
5859 definitions [term ] = (classifier , subitem [idx ], subcontent )
5960
6061 return definitions
@@ -123,7 +124,7 @@ def print_action_groups(data, nested_content, markdown_help=False, settings=None
123124
124125 local_definitions = definitions
125126 if len (subcontent ) > 0 :
126- local_definitions = { k : v for k , v in definitions .items ()}
127+ local_definitions = dict ( definitions .items ())
127128 for k , v in map_nested_definitions (subcontent ).items ():
128129 local_definitions [k ] = v
129130
@@ -267,23 +268,23 @@ def ensure_unique_ids(items):
267268
268269class ArgParseDirective (Directive ):
269270 has_content = True
270- option_spec = dict (
271- module = unchanged ,
272- func = unchanged ,
273- ref = unchanged ,
274- prog = unchanged ,
275- path = unchanged ,
276- nodefault = flag ,
277- nodefaultconst = flag ,
278- filename = unchanged ,
279- manpage = unchanged ,
280- nosubcommands = unchanged ,
281- passparser = flag ,
282- noepilog = unchanged ,
283- nodescription = unchanged ,
284- markdown = flag ,
285- markdownhelp = flag ,
286- )
271+ option_spec = {
272+ ' module' : unchanged ,
273+ ' func' : unchanged ,
274+ ' ref' : unchanged ,
275+ ' prog' : unchanged ,
276+ ' path' : unchanged ,
277+ ' nodefault' : flag ,
278+ ' nodefaultconst' : flag ,
279+ ' filename' : unchanged ,
280+ ' manpage' : unchanged ,
281+ ' nosubcommands' : unchanged ,
282+ ' passparser' : flag ,
283+ ' noepilog' : unchanged ,
284+ ' nodescription' : unchanged ,
285+ ' markdown' : flag ,
286+ ' markdownhelp' : flag ,
287+ }
287288
288289 def _construct_manpage_specific_structure (self , parser_info ):
289290 """
@@ -489,25 +490,26 @@ def run(self):
489490 attr_name = self .options ['func' ]
490491 func = mod [attr_name ]
491492 else :
492- raise self .error (
493- ':module: and :func: should be specified, or :ref:, or :filename: and :func:'
494- )
493+ msg = ':module: and :func: should be specified, or :ref:, or :filename: and :func:'
494+ raise self .error (msg )
495495
496496 # Skip this if we're dealing with a local file, since it obviously can't be imported
497497 if 'filename' not in self .options :
498498 try :
499499 mod = importlib .import_module (module_name )
500500 except ImportError as exc :
501- raise self . error (
501+ msg = (
502502 f'Failed to import "{ attr_name } " from "{ module_name } ".\n '
503503 f'{ sys .exc_info ()[1 ]} '
504- ) from exc
504+ )
505+ raise self .error (msg ) from exc
505506
506507 if not hasattr (mod , attr_name ):
507- raise self . error (
508+ msg = (
508509 f'Module "{ module_name } " has no attribute "{ attr_name } "\n '
509510 f'Incorrect argparse :module: or :func: values?'
510511 )
512+ raise self .error (msg )
511513 func = getattr (mod , attr_name )
512514
513515 if isinstance (func , ArgumentParser ):
@@ -542,9 +544,9 @@ def run(self):
542544 self .state .nested_parse (self .content , self .content_offset , nested_content )
543545 nested_content = nested_content .children
544546 # add common content between
545- for item in nested_content :
546- if not isinstance (item , nodes .definition_list ):
547- items . append ( item )
547+ items += [
548+ item for item in nested_content if not isinstance (item , nodes .definition_list )
549+ ]
548550
549551 markdown_help = False
550552 if 'markdownhelp' in self .options :
0 commit comments