MCPcopy Index your code
hub / github.com/ipython/ipython / back_unicode_name_matches

Function back_unicode_name_matches

IPython/core/completer.py:1733–1772  ·  view source on GitHub ↗

Match Unicode characters back to Unicode name This does ``☃`` -> ``\\snowman`` Note that snowman is not a valid python3 combining character but will be expanded. Though it will not recombine back to the snowman character by the completion machinery. This will not either back-comp

(text: str)

Source from the content-addressed store, hash-verified

1731
1732
1733def back_unicode_name_matches(text: str) -> tuple[str, Sequence[str]]:
1734 """Match Unicode characters back to Unicode name
1735
1736 This does ``☃`` -> ``\\snowman``
1737
1738 Note that snowman is not a valid python3 combining character but will be expanded.
1739 Though it will not recombine back to the snowman character by the completion machinery.
1740
1741 This will not either back-complete standard sequences like \\n, \\b ...
1742
1743 .. deprecated:: 8.6
1744 You can use :meth:`back_unicode_name_matcher` instead.
1745
1746 Returns
1747 =======
1748
1749 Return a tuple with two elements:
1750
1751 - The Unicode character that was matched (preceded with a backslash), or
1752 empty string,
1753 - a sequence (of 1), name for the match Unicode character, preceded by
1754 backslash, or empty if no match.
1755 """
1756 if len(text)<2:
1757 return '', ()
1758 maybe_slash = text[-2]
1759 if maybe_slash != '\\':
1760 return '', ()
1761
1762 char = text[-1]
1763 # no expand on quote for completion in strings.
1764 # nor backcomplete standard ascii keys
1765 if char in string.ascii_letters or char in ('"',"'"):
1766 return '', ()
1767 try :
1768 unic = unicodedata.name(char)
1769 return '\\'+char,('\\'+unic,)
1770 except KeyError:
1771 pass
1772 return '', ()
1773
1774
1775@context_matcher()

Callers 1

Calls 1

nameMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…