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