##// END OF EJS Templates
MAINT: Don't use traitlets for lazy init of unicode names.
Scott Sanderson -
Show More
@@ -1059,21 +1059,6 b' class IPCompleter(Completer):'
1059 help="Template for path at which to output profile data for completions."
1059 help="Template for path at which to output profile data for completions."
1060 ).tag(config=True)
1060 ).tag(config=True)
1061
1061
1062 _unicode_names = ListTrait(
1063 Unicode(),
1064 help="Lazily-initialized list of unicode code point names.",
1065 )
1066
1067 @default('_unicode_names')
1068 def _unicode_names_default_value(self):
1069 names = []
1070 for c in range(0,0x10FFFF + 1):
1071 try:
1072 names.append(unicodedata.name(chr(c)))
1073 except ValueError:
1074 pass
1075 return names
1076
1077 @observe('limit_to__all__')
1062 @observe('limit_to__all__')
1078 def _limit_to_all_changed(self, change):
1063 def _limit_to_all_changed(self, change):
1079 warnings.warn('`IPython.core.IPCompleter.limit_to__all__` configuration '
1064 warnings.warn('`IPython.core.IPCompleter.limit_to__all__` configuration '
@@ -1151,6 +1136,12 b' class IPCompleter(Completer):'
1151 # This is set externally by InteractiveShell
1136 # This is set externally by InteractiveShell
1152 self.custom_completers = None
1137 self.custom_completers = None
1153
1138
1139 # This is a list of names of unicode characters that can be completed
1140 # into their corresponding unicode value. The list is large, so we
1141 # laziliy initialize it on first use. Consuming code should access this
1142 # attribute through the `@unicode_names` property.
1143 self._unicode_names = None
1144
1154 @property
1145 @property
1155 def matchers(self):
1146 def matchers(self):
1156 """All active matcher routines for completion"""
1147 """All active matcher routines for completion"""
@@ -2127,7 +2118,7 b' class IPCompleter(Completer):'
2127 # initialize it, so we don't want to initialize it unless we're
2118 # initialize it, so we don't want to initialize it unless we're
2128 # actually going to use it.
2119 # actually going to use it.
2129 s = text[slashpos+1:]
2120 s = text[slashpos+1:]
2130 candidates = [x for x in self._unicode_names if x.startswith(s)]
2121 candidates = [x for x in self.unicode_names if x.startswith(s)]
2131 if candidates:
2122 if candidates:
2132 return s, candidates
2123 return s, candidates
2133 else:
2124 else:
@@ -2136,3 +2127,20 b' class IPCompleter(Completer):'
2136 # if text does not start with slash
2127 # if text does not start with slash
2137 else:
2128 else:
2138 return u'', ()
2129 return u'', ()
2130
2131 @property
2132 def unicode_names(self) -> List[str]:
2133 """List of names of unicode code points that can be completed.
2134
2135 The list is lazily initialized on first access.
2136 """
2137 if self._unicode_names is None:
2138 names = []
2139 for c in range(0,0x10FFFF + 1):
2140 try:
2141 names.append(unicodedata.name(chr(c)))
2142 except ValueError:
2143 pass
2144 self._unicode_names = names
2145
2146 return self._unicode_names
General Comments 0
You need to be logged in to leave comments. Login now