1313from cdd .shared .ast_utils import deduplicate
1414from cdd .shared .pure_utils import (
1515 count_iter_items ,
16- pp ,
1716 simple_types ,
1817 sliding_window ,
1918 type_to_name ,
5756 ("List" , " " , "of" ): "List" ,
5857 ("Tuple" , " " , "of" ): "Tuple" ,
5958 ("Dictionary" , " " , "of" ): "Mapping" ,
60- ("One" , " " , "of" ): "Union" ,
6159}
6260
6361
@@ -371,19 +369,8 @@ def _parse_adhoc_doc_for_typ_phase0(doc, words):
371369 word_chars : str = "{0}{1}`'\" /|" .format (string .digits , string .ascii_letters )
372370 sentence_ends : int = - 1
373371 break_the_union : bool = False # lincoln
374- counter = Counter (doc ) # Imperfect because won't catch escaped quote marks
375- balanced_single : bool = counter ["'" ] > 0 and counter ["'" ] & 1 == 0
376- balanced_double : bool = counter ['"' ] > 0 and counter ['"' ] & 1 == 0
377-
378- i : int = 0
379- n : int = len (doc )
380- while i < n :
381- ch : str = doc [i ]
382- if (ch == "'" and balanced_single or ch == '"' and balanced_double ) and (
383- i == 0 or doc [i - 1 ] != "\\ "
384- ):
385- i = eat_quoted (ch , doc , i , words , n )
386- elif (
372+ for i , ch in enumerate (doc ):
373+ if (
387374 ch in word_chars
388375 or ch == "."
389376 and len (doc ) > (i + 1 )
@@ -393,20 +380,14 @@ def _parse_adhoc_doc_for_typ_phase0(doc, words):
393380 ):
394381 words [- 1 ].append (ch )
395382 elif ch in frozenset (("." , ";" , "," )) or ch .isspace ():
396- if words [- 1 ]:
397- words [- 1 ] = "" .join (words [- 1 ])
398- words .append (ch )
399- else :
400- words [- 1 ] = ch
383+ words [- 1 ] = "" .join (words [- 1 ])
384+ words .append (ch )
401385 if ch == "." and sentence_ends == - 1 :
402386 sentence_ends : int = len (words )
403387 elif ch == ";" :
404388 break_the_union = True
405389 words .append ([])
406- i += 1
407390 words [- 1 ] = "" .join (words [- 1 ])
408- if not words [- 1 ]:
409- del words [- 1 ]
410391 candidate_type : Optional [str ] = next (
411392 map (
412393 adhoc_type_to_type .__getitem__ ,
@@ -433,47 +414,4 @@ def _parse_adhoc_doc_for_typ_phase0(doc, words):
433414 return candidate_type , fst_sentence , sentence
434415
435416
436- def eat_quoted (ch , doc , chomp_start_idx , words , n ):
437- """
438- Chomp from quoted character `ch` to quoted character `ch`
439-
440- :param ch: Character of `'` or `"`
441- :type ch: ```Literal["'", '"']```
442-
443- :param doc: Possibly ambiguous docstring for argument, that *might* hint as to the type
444- :type doc: ```str```
445-
446- :param chomp_start_idx: chomp_start_idx
447- :type chomp_start_idx: ```int```
448-
449- :param words: Words
450- :type words: ```List[Union[List[str], str]]```
451-
452- :param n: Length of `doc`
453- :type n: ```int```
454-
455- :return: chomp_end_idx
456- :rtype: ```int```
457- """
458- chomp_end_idx : int = next (
459- filter (
460- lambda _chomp_end_idx : doc [_chomp_end_idx + 1 ] != ch
461- or doc [_chomp_end_idx ] == "\\ " ,
462- range (chomp_start_idx , n ),
463- ),
464- chomp_start_idx ,
465- )
466- quoted_str : str = doc [chomp_start_idx :chomp_end_idx ]
467- from operator import iadd
468-
469- pp ({"b4::words" : words , '"".join(words[-1])' : "" .join (words [- 1 ])})
470- (
471- iadd (words , (quoted_str , []))
472- if len (words [- 1 ]) == 1 and words [- 1 ][- 1 ] == "`"
473- else iadd (words , ("" .join (words [- 1 ]), quoted_str , []))
474- )
475- pp ({"words" : words })
476- return chomp_end_idx
477-
478-
479417__all__ = ["parse_adhoc_doc_for_typ" ] # type: list[str]
0 commit comments