@@ -930,21 +930,17 @@ def _extract_issue_number(issue):
930930_section_special_patterns ['Tools/Demos' ].add (re .compile ('^dem(?:o|os)?$' , re .I ))
931931
932932
933- def _extract_section_name (section ):
934- if section is None :
935- return None
936-
937- section = raw_section = section .strip ()
938- if not section :
939- sys .exit ("Empty section name!" )
933+ def _find_smart_matches (section ):
934+ # '_', '-' and ' ' are the allowed (user) whitespace separators
935+ sanitized = re .sub (r'[_\- ]' , ' ' , section ).strip ()
936+ if not sanitized :
937+ return []
940938
941939 matches = []
942-
943- # '_', '-', ' ' and '/' are the allowed (user) separators
944- sanitized = re .sub (r'[_\- /]' , ' ' , section )
945940 section_words = re .split (r'\s+' , sanitized )
946941 # ' ' and '/' are the separators used by known sections
947942 section_pattern = r'[ /]' .join (map (re .escape , section_words ))
943+
948944 section_pattern = re .compile (section_pattern , re .I )
949945 for section_name in sections :
950946 # try to use the input as the pattern to match against known names
@@ -959,7 +955,7 @@ def _extract_section_name(section):
959955 break
960956
961957 if not matches :
962- # try to use the input as the prefix of a known section name
958+ # try to use the input as the prefix of a flattened section name
963959 normalized_prefix = '' .join (section_words ).lower ()
964960 for section_name , normalized in _section_names_lower_nosep .items ():
965961 if (
@@ -968,6 +964,24 @@ def _extract_section_name(section):
968964 ):
969965 matches .append (section_name )
970966
967+ return matches
968+
969+ def _extract_section_name (section ):
970+ if section is None :
971+ return None
972+
973+ section = raw_section = section .strip ()
974+ if not section :
975+ sys .exit ("Empty section name!" )
976+
977+ matches = []
978+ # try a simple exact match
979+ for section_name in sections :
980+ if section_name .lower ().startswith (section .lower ()):
981+ matches .append (section_name )
982+ # try a more complex algorithm if we are unlucky
983+ matches = matches or _find_smart_matches (section )
984+
971985 if not matches :
972986 sys .exit (f"Invalid section name: { raw_section !r} \n \n "
973987 f"Choose from the following table:\n \n "
0 commit comments