Checks the pre-condition that @string has the format that you would expect of `leaf.value` where `leaf` is some Leaf such that `leaf.type == token.STRING`. A more precise description of the pre-conditions that are checked are listed below. Pre-conditions: * @string star
(string: str)
| 106 | |
| 107 | |
| 108 | def assert_is_leaf_string(string: str) -> None: |
| 109 | """ |
| 110 | Checks the pre-condition that @string has the format that you would expect |
| 111 | of `leaf.value` where `leaf` is some Leaf such that `leaf.type == |
| 112 | token.STRING`. A more precise description of the pre-conditions that are |
| 113 | checked are listed below. |
| 114 | |
| 115 | Pre-conditions: |
| 116 | * @string starts with either ', ", <prefix>', or <prefix>" where |
| 117 | `set(<prefix>)` is some subset of `set(STRING_PREFIX_CHARS)`. |
| 118 | * @string ends with a quote character (' or "). |
| 119 | |
| 120 | Raises: |
| 121 | AssertionError(...) if the pre-conditions listed above are not |
| 122 | satisfied. |
| 123 | """ |
| 124 | dquote_idx = string.find('"') |
| 125 | squote_idx = string.find("'") |
| 126 | if -1 in [dquote_idx, squote_idx]: |
| 127 | quote_idx = max(dquote_idx, squote_idx) |
| 128 | else: |
| 129 | quote_idx = min(squote_idx, dquote_idx) |
| 130 | |
| 131 | assert ( |
| 132 | 0 <= quote_idx < len(string) - 1 |
| 133 | ), f"{string!r} is missing a starting quote character (' or \")." |
| 134 | assert string[-1] in ( |
| 135 | "'", |
| 136 | '"', |
| 137 | ), f"{string!r} is missing an ending quote character (' or \")." |
| 138 | assert set(string[:quote_idx]).issubset( |
| 139 | set(STRING_PREFIX_CHARS) |
| 140 | ), f"{set(string[:quote_idx])} is NOT a subset of {set(STRING_PREFIX_CHARS)}." |
| 141 | |
| 142 | |
| 143 | def normalize_string_prefix(s: str) -> str: |
no outgoing calls
no test coverage detected