MCPcopy
hub / github.com/psf/black / _iter_nameescape_slices

Method _iter_nameescape_slices

src/black/trans.py:1746–1775  ·  view source on GitHub ↗

r""" Yields: All ranges of @string which, if @string were to be split there, would result in the splitting of an \N{...} expression (which is NOT allowed).

(self, string: str)

Source from the content-addressed store, hash-verified

1744 yield Ok(last_line)
1745
1746 def _iter_nameescape_slices(self, string: str) -> Iterator[tuple[Index, Index]]:
1747 r"""
1748 Yields:
1749 All ranges of @string which, if @string were to be split there,
1750 would result in the splitting of an \N{...} expression (which is NOT
1751 allowed).
1752 """
1753 # True - the previous backslash was unescaped
1754 # False - the previous backslash was escaped *or* there was no backslash
1755 previous_was_unescaped_backslash = False
1756 it = iter(enumerate(string))
1757 for idx, c in it:
1758 if c == "\\":
1759 previous_was_unescaped_backslash = not previous_was_unescaped_backslash
1760 continue
1761 if not previous_was_unescaped_backslash or c != "N":
1762 previous_was_unescaped_backslash = False
1763 continue
1764 previous_was_unescaped_backslash = False
1765
1766 begin = idx - 1 # the position of backslash before \N{...}
1767 for idx, c in it:
1768 if c == "}":
1769 end = idx
1770 break
1771 else:
1772 # malformed nameescape expression?
1773 # should have been detected by AST parsing earlier...
1774 raise RuntimeError(f"{self.__class__.__name__} LOGIC ERROR!")
1775 yield begin, end
1776
1777 def _iter_fexpr_slices(self, string: str) -> Iterator[tuple[Index, Index]]:
1778 """

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected