|
4 | 4 | # LICENSE file in the root directory of this source tree. |
5 | 5 |
|
6 | 6 | from enum import auto, Enum |
7 | | -from typing import Any, Callable, final, Iterable, Optional, Sequence, Tuple, Union |
| 7 | +from typing import Any, Callable, final, Optional, Sequence, Tuple |
8 | 8 |
|
9 | | -from libcst._parser.parso.pgen2.generator import ReservedString |
10 | | -from libcst._parser.parso.python.token import PythonTokenTypes, TokenType |
11 | | -from libcst._parser.types.token import Token |
12 | 9 | from libcst._tabs import expand_tabs |
13 | 10 |
|
14 | | -_EOF_STR: str = "end of file (EOF)" |
15 | | -_INDENT_STR: str = "an indent" |
16 | | -_DEDENT_STR: str = "a dedent" |
| 11 | + |
17 | 12 | _NEWLINE_CHARS: str = "\r\n" |
18 | 13 |
|
19 | 14 |
|
20 | 15 | class EOFSentinel(Enum): |
21 | 16 | EOF = auto() |
22 | 17 |
|
23 | 18 |
|
24 | | -def get_expected_str( |
25 | | - encountered: Union[Token, EOFSentinel], |
26 | | - expected: Union[Iterable[Union[TokenType, ReservedString]], EOFSentinel], |
27 | | -) -> str: |
28 | | - if ( |
29 | | - isinstance(encountered, EOFSentinel) |
30 | | - or encountered.type is PythonTokenTypes.ENDMARKER |
31 | | - ): |
32 | | - encountered_str = _EOF_STR |
33 | | - elif encountered.type is PythonTokenTypes.INDENT: |
34 | | - encountered_str = _INDENT_STR |
35 | | - elif encountered.type is PythonTokenTypes.DEDENT: |
36 | | - encountered_str = _DEDENT_STR |
37 | | - else: |
38 | | - encountered_str = repr(encountered.string) |
39 | | - |
40 | | - if isinstance(expected, EOFSentinel): |
41 | | - expected_names = [_EOF_STR] |
42 | | - else: |
43 | | - expected_names = sorted( |
44 | | - [ |
45 | | - repr(el.name) if isinstance(el, TokenType) else repr(el.value) |
46 | | - for el in expected |
47 | | - ] |
48 | | - ) |
| 19 | +class CSTLogicError(Exception): |
| 20 | + """General purpose internal error within LibCST itself.""" |
49 | 21 |
|
50 | | - if len(expected_names) > 10: |
51 | | - # There's too many possibilities, so it's probably not useful to list them. |
52 | | - # Instead, let's just abbreviate the message. |
53 | | - return f"Unexpectedly encountered {encountered_str}." |
54 | | - else: |
55 | | - if len(expected_names) == 1: |
56 | | - expected_str = expected_names[0] |
57 | | - else: |
58 | | - expected_str = f"{', '.join(expected_names[:-1])}, or {expected_names[-1]}" |
59 | | - return f"Encountered {encountered_str}, but expected {expected_str}." |
| 22 | + pass |
60 | 23 |
|
61 | 24 |
|
62 | 25 | # pyre-fixme[2]: 'Any' type isn't pyre-strict. |
|
0 commit comments