Show More
@@ -138,6 +138,7 b' class MultipleInstanceError(Exception):' | |||||
138 | class InteractiveShell(Configurable, Magic): |
|
138 | class InteractiveShell(Configurable, Magic): | |
139 | """An enhanced, interactive shell for Python.""" |
|
139 | """An enhanced, interactive shell for Python.""" | |
140 |
|
140 | |||
|
141 | _instance = None | |||
141 | autocall = Enum((0,1,2), default_value=1, config=True) |
|
142 | autocall = Enum((0,1,2), default_value=1, config=True) | |
142 | # TODO: remove all autoindent logic and put into frontends. |
|
143 | # TODO: remove all autoindent logic and put into frontends. | |
143 | # We can't do this yet because even runlines uses the autoindent. |
|
144 | # We can't do this yet because even runlines uses the autoindent. | |
@@ -269,20 +270,22 b' class InteractiveShell(Configurable, Magic):' | |||||
269 | @classmethod |
|
270 | @classmethod | |
270 | def instance(cls, *args, **kwargs): |
|
271 | def instance(cls, *args, **kwargs): | |
271 | """Returns a global InteractiveShell instance.""" |
|
272 | """Returns a global InteractiveShell instance.""" | |
272 |
if |
|
273 | if cls._instance is None: | |
273 |
|
|
274 | inst = cls(*args, **kwargs) | |
274 | # Now make sure that the instance will also be returned by |
|
275 | # Now make sure that the instance will also be returned by | |
275 | # the subclasses instance attribute. |
|
276 | # the subclasses instance attribute. | |
276 |
for subclass in cls.mro() |
|
277 | for subclass in cls.mro(): | |
277 | if issubclass(subclass, InteractiveShell): |
|
278 | if issubclass(cls, subclass) and issubclass(subclass, InteractiveShell): | |
278 |
|
|
279 | subclass._instance = inst | |
279 | subclass._instance = cls._instance |
|
280 | else: | |
280 |
|
|
281 | break | |
281 | raise MultipleInstanceError( |
|
282 | if isinstance(cls._instance, cls): | |
282 | 'Multiple conflicting subclass of ' |
|
283 | return cls._instance | |
283 | 'InteractiveShell have been created.' |
|
284 | else: | |
284 | ) |
|
285 | raise MultipleInstanceError( | |
285 | return cls._instance |
|
286 | 'Multiple incompatible subclass instances of ' | |
|
287 | 'InteractiveShell are being created.' | |||
|
288 | ) | |||
286 |
|
289 | |||
287 | @classmethod |
|
290 | @classmethod | |
288 | def initialized(cls): |
|
291 | def initialized(cls): |
General Comments 0
You need to be logged in to leave comments.
Login now