##// END OF EJS Templates
Fixes for metaclass syntax
Thomas Kluyver -
Show More
@@ -36,7 +36,7 b' from IPython.lib import pretty'
36 from IPython.utils.traitlets import (
36 from IPython.utils.traitlets import (
37 Bool, Dict, Integer, Unicode, CUnicode, ObjectName, List,
37 Bool, Dict, Integer, Unicode, CUnicode, ObjectName, List,
38 )
38 )
39 from IPython.utils.py3compat import unicode_to_str
39 from IPython.utils.py3compat import unicode_to_str, with_metaclass
40
40
41
41
42 #-----------------------------------------------------------------------------
42 #-----------------------------------------------------------------------------
@@ -176,7 +176,7 b' class DisplayFormatter(Configurable):'
176 #-----------------------------------------------------------------------------
176 #-----------------------------------------------------------------------------
177
177
178
178
179 class FormatterABC(object):
179 class FormatterABC(with_metaclass(abc.ABCMeta, object)):
180 """ Abstract base class for Formatters.
180 """ Abstract base class for Formatters.
181
181
182 A formatter is a callable class that is responsible for computing the
182 A formatter is a callable class that is responsible for computing the
@@ -184,7 +184,6 b' class FormatterABC(object):'
184 an HTML formatter would have a format type of `text/html` and would return
184 an HTML formatter would have a format type of `text/html` and would return
185 the HTML representation of the object when called.
185 the HTML representation of the object when called.
186 """
186 """
187 __metaclass__ = abc.ABCMeta
188
187
189 # The format type of the data returned, usually a MIME type.
188 # The format type of the data returned, usually a MIME type.
190 format_type = 'text/plain'
189 format_type = 'text/plain'
@@ -6,6 +6,7 b' from io import StringIO'
6 from IPython.core.splitinput import LineInfo
6 from IPython.core.splitinput import LineInfo
7 from IPython.utils import tokenize2
7 from IPython.utils import tokenize2
8 from IPython.utils.openpy import cookie_comment_re
8 from IPython.utils.openpy import cookie_comment_re
9 from IPython.utils.py3compat import with_metaclass
9 from IPython.utils.tokenize2 import generate_tokens, untokenize, TokenError
10 from IPython.utils.tokenize2 import generate_tokens, untokenize, TokenError
10
11
11 #-----------------------------------------------------------------------------
12 #-----------------------------------------------------------------------------
@@ -33,9 +34,8 b' ESC_SEQUENCES = [ESC_SHELL, ESC_SH_CAP, ESC_HELP ,\\'
33 ESC_QUOTE, ESC_QUOTE2, ESC_PAREN ]
34 ESC_QUOTE, ESC_QUOTE2, ESC_PAREN ]
34
35
35
36
36 class InputTransformer(object):
37 class InputTransformer(with_metaclass(abc.ABCMeta, object)):
37 """Abstract base class for line-based input transformers."""
38 """Abstract base class for line-based input transformers."""
38 __metaclass__ = abc.ABCMeta
39
39
40 @abc.abstractmethod
40 @abc.abstractmethod
41 def push(self, line):
41 def push(self, line):
@@ -68,7 +68,8 b' from IPython.utils.ipstruct import Struct'
68 from IPython.utils.path import get_home_dir, get_ipython_dir, get_py_filename, unquote_filename
68 from IPython.utils.path import get_home_dir, get_ipython_dir, get_py_filename, unquote_filename
69 from IPython.utils.pickleshare import PickleShareDB
69 from IPython.utils.pickleshare import PickleShareDB
70 from IPython.utils.process import system, getoutput
70 from IPython.utils.process import system, getoutput
71 from IPython.utils.py3compat import builtin_mod, unicode_type, string_types
71 from IPython.utils.py3compat import (builtin_mod, unicode_type, string_types,
72 with_metaclass)
72 from IPython.utils.strdispatch import StrDispatch
73 from IPython.utils.strdispatch import StrDispatch
73 from IPython.utils.syspathcontext import prepended_to_syspath
74 from IPython.utils.syspathcontext import prepended_to_syspath
74 from IPython.utils.text import (format_screen, LSString, SList,
75 from IPython.utils.text import (format_screen, LSString, SList,
@@ -3157,8 +3158,7 b' class InteractiveShell(SingletonConfigurable):'
3157 self.restore_sys_module_state()
3158 self.restore_sys_module_state()
3158
3159
3159
3160
3160 class InteractiveShellABC(object):
3161 class InteractiveShellABC(with_metaclass(abc.ABCMeta, object)):
3161 """An abstract base class for InteractiveShell."""
3162 """An abstract base class for InteractiveShell."""
3162 __metaclass__ = abc.ABCMeta
3163
3163
3164 InteractiveShellABC.register(InteractiveShell)
3164 InteractiveShellABC.register(InteractiveShell)
@@ -11,19 +11,18 b''
11 # Imports
11 # Imports
12 #-----------------------------------------------------------------------------
12 #-----------------------------------------------------------------------------
13
13
14 # Standard library imports
15 import abc
14 import abc
16
15
16 from IPython.utils.py3compat import with_metaclass
17
17 #-----------------------------------------------------------------------------
18 #-----------------------------------------------------------------------------
18 # Channels
19 # Channels
19 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
20
21
21
22
22 class ChannelABC(object):
23 class ChannelABC(with_metaclass(abc.ABCMeta, object)):
23 """A base class for all channel ABCs."""
24 """A base class for all channel ABCs."""
24
25
25 __metaclass__ = abc.ABCMeta
26
27 @abc.abstractmethod
26 @abc.abstractmethod
28 def start(self):
27 def start(self):
29 pass
28 pass
@@ -11,14 +11,15 b''
11 # Imports
11 # Imports
12 #-----------------------------------------------------------------------------
12 #-----------------------------------------------------------------------------
13
13
14 # Standard library imports
15 import abc
14 import abc
16
15
16 from IPython.utils.py3compat import with_metaclass
17
17 #-----------------------------------------------------------------------------
18 #-----------------------------------------------------------------------------
18 # Main kernel client class
19 # Main kernel client class
19 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
20
21
21 class KernelClientABC(object):
22 class KernelClientABC(with_metaclass(abc.ABCMeta, object)):
22 """KernelManager ABC.
23 """KernelManager ABC.
23
24
24 The docstrings for this class can be found in the base implementation:
25 The docstrings for this class can be found in the base implementation:
@@ -26,8 +27,6 b' class KernelClientABC(object):'
26 `IPython.kernel.client.KernelClient`
27 `IPython.kernel.client.KernelClient`
27 """
28 """
28
29
29 __metaclass__ = abc.ABCMeta
30
31 @abc.abstractproperty
30 @abc.abstractproperty
32 def kernel(self):
31 def kernel(self):
33 pass
32 pass
@@ -23,14 +23,13 b' import zmq'
23
23
24 # Local imports.
24 # Local imports.
25 from IPython.utils.traitlets import HasTraits, Instance, Int
25 from IPython.utils.traitlets import HasTraits, Instance, Int
26 from IPython.utils.py3compat import with_metaclass
26
27
27 #-----------------------------------------------------------------------------
28 #-----------------------------------------------------------------------------
28 # Generic socket interface
29 # Generic socket interface
29 #-----------------------------------------------------------------------------
30 #-----------------------------------------------------------------------------
30
31
31 class SocketABC(object):
32 class SocketABC(with_metaclass(abc.ABCMeta, object)):
32 __metaclass__ = abc.ABCMeta
33
34 @abc.abstractmethod
33 @abc.abstractmethod
35 def recv_multipart(self, flags=0, copy=True, track=False):
34 def recv_multipart(self, flags=0, copy=True, track=False):
36 raise NotImplementedError
35 raise NotImplementedError
@@ -11,19 +11,18 b''
11 # Imports
11 # Imports
12 #-----------------------------------------------------------------------------
12 #-----------------------------------------------------------------------------
13
13
14 # Standard library imports.
15 import abc
14 import abc
16
15
16 from IPython.utils.py3compat import with_metaclass
17
17 #-----------------------------------------------------------------------------
18 #-----------------------------------------------------------------------------
18 # Channels
19 # Channels
19 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
20
21
21
22
22 class ChannelABC(object):
23 class ChannelABC(with_metaclass(abc.ABCMeta, object)):
23 """A base class for all channel ABCs."""
24 """A base class for all channel ABCs."""
24
25
25 __metaclass__ = abc.ABCMeta
26
27 @abc.abstractmethod
26 @abc.abstractmethod
28 def start(self):
27 def start(self):
29 pass
28 pass
@@ -130,7 +129,7 b' class HBChannelABC(ChannelABC):'
130 # Main kernel manager class
129 # Main kernel manager class
131 #-----------------------------------------------------------------------------
130 #-----------------------------------------------------------------------------
132
131
133 class KernelManagerABC(object):
132 class KernelManagerABC(with_metaclass(abc.ABCMeta, object)):
134 """KernelManager ABC.
133 """KernelManager ABC.
135
134
136 The docstrings for this class can be found in the base implementation:
135 The docstrings for this class can be found in the base implementation:
@@ -138,8 +137,6 b' class KernelManagerABC(object):'
138 `IPython.kernel.kernelmanager.KernelManager`
137 `IPython.kernel.kernelmanager.KernelManager`
139 """
138 """
140
139
141 __metaclass__ = abc.ABCMeta
142
143 @abc.abstractproperty
140 @abc.abstractproperty
144 def kernel(self):
141 def kernel(self):
145 pass
142 pass
@@ -21,6 +21,7 b' from IPython.config.configurable import LoggingConfigurable'
21 from IPython.core.inputsplitter import ESC_SEQUENCES
21 from IPython.core.inputsplitter import ESC_SEQUENCES
22 from IPython.qt.rich_text import HtmlExporter
22 from IPython.qt.rich_text import HtmlExporter
23 from IPython.qt.util import MetaQObjectHasTraits, get_font
23 from IPython.qt.util import MetaQObjectHasTraits, get_font
24 from IPython.utils.py3compat import with_metaclass
24 from IPython.utils.text import columnize
25 from IPython.utils.text import columnize
25 from IPython.utils.traitlets import Bool, Enum, Integer, Unicode
26 from IPython.utils.traitlets import Bool, Enum, Integer, Unicode
26 from .ansi_code_processor import QtAnsiCodeProcessor
27 from .ansi_code_processor import QtAnsiCodeProcessor
@@ -69,7 +70,7 b' def is_letter_or_number(char):'
69 # Classes
70 # Classes
70 #-----------------------------------------------------------------------------
71 #-----------------------------------------------------------------------------
71
72
72 class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):
73 class ConsoleWidget(with_metaclass(MetaQObjectHasTraits, type('NewBase', (LoggingConfigurable, QtGui.QWidget), {}))):
73 """ An abstract base class for console-type widgets. This class has
74 """ An abstract base class for console-type widgets. This class has
74 functionality for:
75 functionality for:
75
76
@@ -82,7 +83,6 b' class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):'
82 ConsoleWidget also provides a number of utility methods that will be
83 ConsoleWidget also provides a number of utility methods that will be
83 convenient to implementors of a console-style widget.
84 convenient to implementors of a console-style widget.
84 """
85 """
85 __metaclass__ = MetaQObjectHasTraits
86
86
87 #------ Configuration ------------------------------------------------------
87 #------ Configuration ------------------------------------------------------
88
88
@@ -168,27 +168,22 b' class QtHBChannelMixin(ChannelQObject):'
168 self.kernel_died.emit(since_last_heartbeat)
168 self.kernel_died.emit(since_last_heartbeat)
169
169
170
170
171 class QtKernelRestarterMixin(HasTraits, SuperQObject):
171 class QtKernelRestarterMixin(MetaQObjectHasTraits('NewBase', (HasTraits, SuperQObject), {})):
172
172
173 __metaclass__ = MetaQObjectHasTraits
174 _timer = None
173 _timer = None
175
174
176
175
177 class QtKernelManagerMixin(HasTraits, SuperQObject):
176 class QtKernelManagerMixin(MetaQObjectHasTraits('NewBase', (HasTraits, SuperQObject), {})):
178 """ A KernelClient that provides signals and slots.
177 """ A KernelClient that provides signals and slots.
179 """
178 """
180
179
181 __metaclass__ = MetaQObjectHasTraits
182
183 kernel_restarted = QtCore.Signal()
180 kernel_restarted = QtCore.Signal()
184
181
185
182
186 class QtKernelClientMixin(HasTraits, SuperQObject):
183 class QtKernelClientMixin(MetaQObjectHasTraits('NewBase', (HasTraits, SuperQObject), {})):
187 """ A KernelClient that provides signals and slots.
184 """ A KernelClient that provides signals and slots.
188 """
185 """
189
186
190 __metaclass__ = MetaQObjectHasTraits
191
192 # Emitted when the kernel client has started listening.
187 # Emitted when the kernel client has started listening.
193 started_channels = QtCore.Signal()
188 started_channels = QtCore.Signal()
194
189
@@ -208,3 +208,28 b' else:'
208 else:
208 else:
209 filename = fname
209 filename = fname
210 builtin_mod.execfile(filename, *where)
210 builtin_mod.execfile(filename, *where)
211
212 # Parts below taken from six:
213 # Copyright (c) 2010-2013 Benjamin Peterson
214 #
215 # Permission is hereby granted, free of charge, to any person obtaining a copy
216 # of this software and associated documentation files (the "Software"), to deal
217 # in the Software without restriction, including without limitation the rights
218 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
219 # copies of the Software, and to permit persons to whom the Software is
220 # furnished to do so, subject to the following conditions:
221 #
222 # The above copyright notice and this permission notice shall be included in all
223 # copies or substantial portions of the Software.
224 #
225 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
226 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
227 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
228 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
229 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
230 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
231 # SOFTWARE.
232
233 def with_metaclass(meta, *bases):
234 """Create a base class with a metaclass."""
235 return meta("NewBase", bases, {})
@@ -394,9 +394,7 b' class MetaHasTraits(type):'
394 v.this_class = cls
394 v.this_class = cls
395 super(MetaHasTraits, cls).__init__(name, bases, classdict)
395 super(MetaHasTraits, cls).__init__(name, bases, classdict)
396
396
397 class HasTraits(object):
397 class HasTraits(py3compat.with_metaclass(MetaHasTraits, object)):
398
399 __metaclass__ = MetaHasTraits
400
398
401 def __new__(cls, *args, **kw):
399 def __new__(cls, *args, **kw):
402 # This is needed because in Python 2.6 object.__new__ only accepts
400 # This is needed because in Python 2.6 object.__new__ only accepts
General Comments 0
You need to be logged in to leave comments. Login now