diff --git a/dev_scripts/update_pt_data.py b/dev_scripts/update_pt_data.py index f669657337d..88f321ed712 100644 --- a/dev_scripts/update_pt_data.py +++ b/dev_scripts/update_pt_data.py @@ -30,8 +30,8 @@ def parse_oxi_state(): oxi_data = re.sub("[\n\r]", "", oxi_data) patt = re.compile("(.*?)", re.MULTILINE) - for m in patt.finditer(oxi_data): - line = m.group(1) + for match in patt.finditer(oxi_data): + line = match[1] line = re.sub("", "", line) line = re.sub("()+", "", line) line = re.sub("]*>", "", line) @@ -39,15 +39,15 @@ def parse_oxi_state(): oxi_states = [] common_oxi = [] for tok in re.split("", line.strip()): - m2 = re.match(r"([A-Z][a-z]*)", tok) - if m2: - el = m2.group(1) + match2 = re.match(r"([A-Z][a-z]*)", tok) + if match2: + el = match2[1] else: - m3 = re.match(r"()*([\+\-]\d)()*", tok) - if m3: - oxi_states += [int(m3.group(2))] - if m3.group(1): - common_oxi += [int(m3.group(2))] + match3 = re.match(r"()*([\+\-]\d)()*", tok) + if match3: + oxi_states += [int(match3[2])] + if match3[1]: + common_oxi += [int(match3[2])] if el in data: del data[el]["Max oxidation state"] del data[el]["Min oxidation state"] diff --git a/pymatgen/analysis/reaction_calculator.py b/pymatgen/analysis/reaction_calculator.py index a98876d6615..456e6ea97d9 100644 --- a/pymatgen/analysis/reaction_calculator.py +++ b/pymatgen/analysis/reaction_calculator.py @@ -283,8 +283,8 @@ def from_str(cls, rxn_str: str) -> Self: def get_comp_amt(comp_str): return { - Composition(m.group(2)): float(m.group(1) or 1) - for m in re.finditer(r"([\d\.]*(?:[eE]-?[\d\.]+)?)\s*([A-Z][\w\.\(\)]*)", comp_str) + Composition(match[2]): float(match[1] or 1) + for match in re.finditer(r"([\d\.]*(?:[eE]-?[\d\.]+)?)\s*([A-Z][\w\.\(\)]*)", comp_str) } return BalancedReaction(get_comp_amt(rct_str), get_comp_amt(prod_str)) diff --git a/pymatgen/util/string.py b/pymatgen/util/string.py index c8d1703bb87..44f7aef08a7 100644 --- a/pymatgen/util/string.py +++ b/pymatgen/util/string.py @@ -71,13 +71,13 @@ def to_unicode_string(self): with systems where the sub and superscripts are pure integers. """ str_ = self.to_latex_string() - for m in re.finditer(r"\$_\{(\d+)\}\$", str_): - s1 = m.group() - s2 = [SUBSCRIPT_UNICODE[s] for s in m.group(1)] + for match in re.finditer(r"\$_\{(\d+)\}\$", str_): + s1 = match.group() + s2 = [SUBSCRIPT_UNICODE[s] for s in match[1]] str_ = str_.replace(s1, "".join(s2)) - for m in re.finditer(r"\$\^\{([\d\+\-]+)\}\$", str_): - s1 = m.group() - s2 = [SUPERSCRIPT_UNICODE[s] for s in m.group(1)] + for match in re.finditer(r"\$\^\{([\d\+\-]+)\}\$", str_): + s1 = match.group() + s2 = [SUPERSCRIPT_UNICODE[s] for s in match[1]] str_ = str_.replace(s1, "".join(s2)) return str_