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