| 135 | |
| 136 | class ConversionSpecifier: |
| 137 | def __init__( |
| 138 | self, match: Match[str], start_pos: int = -1, non_standard_format_spec: bool = False |
| 139 | ) -> None: |
| 140 | self.whole_seq = match.group() |
| 141 | self.start_pos = start_pos |
| 142 | |
| 143 | m_dict = match.groupdict() |
| 144 | self.key = m_dict.get("key") |
| 145 | |
| 146 | # Replace unmatched optional groups with empty matches (for convenience). |
| 147 | self.conv_type = m_dict.get("type") or "" |
| 148 | self.flags = m_dict.get("flags") or "" |
| 149 | self.width = m_dict.get("width") or "" |
| 150 | self.precision = m_dict.get("precision") or "" |
| 151 | |
| 152 | # Used only for str.format() calls (it may be custom for types with __format__()). |
| 153 | self.format_spec = m_dict.get("format_spec") |
| 154 | self.non_standard_format_spec = non_standard_format_spec |
| 155 | # Used only for str.format() calls. |
| 156 | self.conversion = m_dict.get("conversion") |
| 157 | # Full formatted expression (i.e. key plus following attributes and/or indexes). |
| 158 | # Used only for str.format() calls. |
| 159 | self.field = m_dict.get("field") |
| 160 | |
| 161 | def has_key(self) -> bool: |
| 162 | return self.key is not None |