##// END OF EJS Templates
TST: Simplify `NamedInstanceClass`...
Nikita Kniazev -
Show More
@@ -191,25 +191,16 b' def test_line_split():'
191 191 check_line_split(sp, [map(str, p) for p in t])
192 192
193 193
194 class NamedInstanceMetaclass(type):
195 def __getitem__(cls, item):
196 return cls.get_instance(item)
194 class NamedInstanceClass:
195 instances = {}
197 196
198
199 class NamedInstanceClass(metaclass=NamedInstanceMetaclass):
200 197 def __init__(self, name):
201 if not hasattr(self.__class__, "instances"):
202 self.__class__.instances = {}
203 self.__class__.instances[name] = self
198 self.instances[name] = self
204 199
205 200 @classmethod
206 201 def _ipython_key_completions_(cls):
207 202 return cls.instances.keys()
208 203
209 @classmethod
210 def get_instance(cls, name):
211 return cls.instances[name]
212
213 204
214 205 class KeyCompletable:
215 206 def __init__(self, things=()):
General Comments 0
You need to be logged in to leave comments. Login now