##// END OF EJS Templates
Merge pull request #8107 from SylvainCorlay/instance_type_allow_none...
Min RK -
r20948:e06b0e15 merge
parent child Browse files
Show More
@@ -34,7 +34,7 b' class MultipleInstanceError(ConfigurableError):'
34 34 class Configurable(HasTraits):
35 35
36 36 config = Instance(Config, (), {})
37 parent = Instance('IPython.config.configurable.Configurable')
37 parent = Instance('IPython.config.configurable.Configurable', allow_none=True)
38 38
39 39 def __init__(self, **kwargs):
40 40 """Create a configurable given a config config.
@@ -193,7 +193,7 b' class AliasManager(Configurable):'
193 193
194 194 default_aliases = List(default_aliases(), config=True)
195 195 user_aliases = List(default_value=[], config=True)
196 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC')
196 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', allow_none=True)
197 197
198 198 def __init__(self, shell=None, **kwargs):
199 199 super(AliasManager, self).__init__(shell=shell, **kwargs)
@@ -146,7 +146,7 b' class BaseIPythonApplication(Application):'
146 146 return d
147 147
148 148 _in_init_profile_dir = False
149 profile_dir = Instance(ProfileDir)
149 profile_dir = Instance(ProfileDir, allow_none=True)
150 150 def _profile_dir_default(self):
151 151 # avoid recursion
152 152 if self._in_init_profile_dir:
@@ -36,7 +36,8 b' HideBuiltin = __HideBuiltin()'
36 36
37 37 class BuiltinTrap(Configurable):
38 38
39 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC')
39 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC',
40 allow_none=True)
40 41
41 42 def __init__(self, shell=None):
42 43 super(BuiltinTrap, self).__init__(shell=shell, config=None)
@@ -29,7 +29,8 b' class DisplayHook(Configurable):'
29 29 that gets called anytime user code returns a value.
30 30 """
31 31
32 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC')
32 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC',
33 allow_none=True)
33 34 exec_result = Instance('IPython.core.interactiveshell.ExecutionResult',
34 35 allow_none=True)
35 36 cull_fraction = Float(0.2)
@@ -46,7 +46,8 b' class ExtensionManager(Configurable):'
46 46 is added to ``sys.path`` automatically.
47 47 """
48 48
49 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC')
49 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC',
50 allow_none=True)
50 51
51 52 def __init__(self, shell=None, **kwargs):
52 53 super(ExtensionManager, self).__init__(shell=shell, **kwargs)
@@ -443,7 +443,8 b' class HistoryManager(HistoryAccessor):'
443 443 # Public interface
444 444
445 445 # An instance of the IPython shell we are attached to
446 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC')
446 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC',
447 allow_none=True)
447 448 # Lists to hold processed and raw history. These start with a blank entry
448 449 # so that we can index them starting from 1
449 450 input_hist_parsed = List([""])
@@ -477,11 +478,12 b' class HistoryManager(HistoryAccessor):'
477 478 db_output_cache = List()
478 479
479 480 # History saving in separate thread
480 save_thread = Instance('IPython.core.history.HistorySavingThread')
481 save_thread = Instance('IPython.core.history.HistorySavingThread',
482 allow_none=True)
481 483 try: # Event is a function returning an instance of _Event...
482 save_flag = Instance(threading._Event)
484 save_flag = Instance(threading._Event, allow_none=True)
483 485 except AttributeError: # ...until Python 3.3, when it's a class.
484 save_flag = Instance(threading.Event)
486 save_flag = Instance(threading.Event, allow_none=True)
485 487
486 488 # Private interface
487 489 # Variables used to store the three last inputs from the user. On each new
@@ -73,7 +73,7 b' from IPython.utils.syspathcontext import prepended_to_syspath'
73 73 from IPython.utils.text import (format_screen, LSString, SList,
74 74 DollarFormatter)
75 75 from IPython.utils.traitlets import (Integer, Bool, CBool, CaselessStrEnum, Enum,
76 List, Unicode, Instance, Type)
76 List, Dict, Unicode, Instance, Type)
77 77 from IPython.utils.warn import warn, error
78 78 import IPython.core.hooks
79 79
@@ -295,7 +295,7 b' class InteractiveShell(SingletonConfigurable):'
295 295 disable_failing_post_execute = CBool(False, config=True,
296 296 help="Don't call post-execute functions that have failed in the past."
297 297 )
298 display_formatter = Instance(DisplayFormatter)
298 display_formatter = Instance(DisplayFormatter, allow_none=True)
299 299 displayhook_class = Type(DisplayHook)
300 300 display_pub_class = Type(DisplayPublisher)
301 301 data_pub_class = None
@@ -435,16 +435,16 b' class InteractiveShell(SingletonConfigurable):'
435 435 default_value='Context', config=True)
436 436
437 437 # Subcomponents of InteractiveShell
438 alias_manager = Instance('IPython.core.alias.AliasManager')
439 prefilter_manager = Instance('IPython.core.prefilter.PrefilterManager')
440 builtin_trap = Instance('IPython.core.builtin_trap.BuiltinTrap')
441 display_trap = Instance('IPython.core.display_trap.DisplayTrap')
442 extension_manager = Instance('IPython.core.extensions.ExtensionManager')
443 payload_manager = Instance('IPython.core.payload.PayloadManager')
444 history_manager = Instance('IPython.core.history.HistoryAccessorBase')
445 magics_manager = Instance('IPython.core.magic.MagicsManager')
446
447 profile_dir = Instance('IPython.core.application.ProfileDir')
438 alias_manager = Instance('IPython.core.alias.AliasManager', allow_none=True)
439 prefilter_manager = Instance('IPython.core.prefilter.PrefilterManager', allow_none=True)
440 builtin_trap = Instance('IPython.core.builtin_trap.BuiltinTrap', allow_none=True)
441 display_trap = Instance('IPython.core.display_trap.DisplayTrap', allow_none=True)
442 extension_manager = Instance('IPython.core.extensions.ExtensionManager', allow_none=True)
443 payload_manager = Instance('IPython.core.payload.PayloadManager', allow_none=True)
444 history_manager = Instance('IPython.core.history.HistoryAccessorBase', allow_none=True)
445 magics_manager = Instance('IPython.core.magic.MagicsManager', allow_none=True)
446
447 profile_dir = Instance('IPython.core.application.ProfileDir', allow_none=True)
448 448 @property
449 449 def profile(self):
450 450 if self.profile_dir is not None:
@@ -453,7 +453,7 b' class InteractiveShell(SingletonConfigurable):'
453 453
454 454
455 455 # Private interface
456 _post_execute = Instance(dict)
456 _post_execute = Dict()
457 457
458 458 # Tracks any GUI loop loaded for pylab
459 459 pylab_gui_select = None
@@ -301,7 +301,7 b' class MagicsManager(Configurable):'
301 301 # A registry of the original objects that we've been given holding magics.
302 302 registry = Dict
303 303
304 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC')
304 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', allow_none=True)
305 305
306 306 auto_magic = Bool(True, config=True, help=
307 307 "Automatically call line magics without requiring explicit % prefix")
@@ -313,7 +313,7 b' class MagicsManager(Configurable):'
313 313 'Automagic is OFF, % prefix IS needed for line magics.',
314 314 'Automagic is ON, % prefix IS NOT needed for line magics.']
315 315
316 user_magics = Instance('IPython.core.magics.UserMagics')
316 user_magics = Instance('IPython.core.magics.UserMagics', allow_none=True)
317 317
318 318 def __init__(self, shell=None, config=None, user_magics=None, **traits):
319 319
@@ -130,7 +130,7 b' class PrefilterManager(Configurable):'
130 130 """
131 131
132 132 multi_line_specials = CBool(True, config=True)
133 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC')
133 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', allow_none=True)
134 134
135 135 def __init__(self, shell=None, **kwargs):
136 136 super(PrefilterManager, self).__init__(shell=shell, **kwargs)
@@ -362,8 +362,8 b' class PrefilterTransformer(Configurable):'
362 362 priority = Integer(100, config=True)
363 363 # Transformers don't currently use shell or prefilter_manager, but as we
364 364 # move away from checkers and handlers, they will need them.
365 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC')
366 prefilter_manager = Instance('IPython.core.prefilter.PrefilterManager')
365 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', allow_none=True)
366 prefilter_manager = Instance('IPython.core.prefilter.PrefilterManager', allow_none=True)
367 367 enabled = Bool(True, config=True)
368 368
369 369 def __init__(self, shell=None, prefilter_manager=None, **kwargs):
@@ -390,8 +390,8 b' class PrefilterChecker(Configurable):'
390 390 """Inspect an input line and return a handler for that line."""
391 391
392 392 priority = Integer(100, config=True)
393 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC')
394 prefilter_manager = Instance('IPython.core.prefilter.PrefilterManager')
393 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', allow_none=True)
394 prefilter_manager = Instance('IPython.core.prefilter.PrefilterManager', allow_none=True)
395 395 enabled = Bool(True, config=True)
396 396
397 397 def __init__(self, shell=None, prefilter_manager=None, **kwargs):
@@ -540,8 +540,8 b' class PrefilterHandler(Configurable):'
540 540
541 541 handler_name = Unicode('normal')
542 542 esc_strings = List([])
543 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC')
544 prefilter_manager = Instance('IPython.core.prefilter.PrefilterManager')
543 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', allow_none=True)
544 prefilter_manager = Instance('IPython.core.prefilter.PrefilterManager', allow_none=True)
545 545
546 546 def __init__(self, shell=None, prefilter_manager=None, **kwargs):
547 547 super(PrefilterHandler, self).__init__(
@@ -278,9 +278,9 b' class UserNSFormatter(Formatter):'
278 278
279 279 class PromptManager(Configurable):
280 280 """This is the primary interface for producing IPython's prompts."""
281 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC')
281 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', allow_none=True)
282 282
283 color_scheme_table = Instance(coloransi.ColorSchemeTable)
283 color_scheme_table = Instance(coloransi.ColorSchemeTable, allow_none=True)
284 284 color_scheme = Unicode('Linux', config=True)
285 285 def _color_scheme_changed(self, name, new_value):
286 286 self.color_scheme_table.set_active_scheme(new_value)
@@ -194,7 +194,8 b' class InteractiveShellApp(Configurable):'
194 194 When False, pylab mode should not import any names into the user namespace.
195 195 """
196 196 )
197 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC')
197 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC',
198 allow_none=True)
198 199
199 200 user_ns = Instance(dict, args=None, allow_none=True)
200 201 def _user_ns_changed(self, name, old, new):
@@ -665,7 +665,7 b' class NotebookApp(BaseIPythonApplication):'
665 665 help='The config manager class to use'
666 666 )
667 667
668 kernel_spec_manager = Instance(KernelSpecManager)
668 kernel_spec_manager = Instance(KernelSpecManager, allow_none=True)
669 669
670 670 kernel_spec_manager_class = Type(
671 671 default_value=KernelSpecManager,
@@ -129,7 +129,7 b' class Widget(LoggingConfigurable):'
129 129 If empty, look in the global registry.""", sync=True)
130 130 _view_name = Unicode(None, allow_none=True, help="""Default view registered in the front-end
131 131 to use to represent the widget.""", sync=True)
132 comm = Instance('IPython.kernel.comm.Comm')
132 comm = Instance('IPython.kernel.comm.Comm', allow_none=True)
133 133
134 134 msg_throttle = Int(3, sync=True, help="""Maximum number of msgs the
135 135 front-end can send before receiving an idle msg from the back-end.""")
@@ -44,7 +44,8 b' class InProcessKernelClient(KernelClient):'
44 44 stdin_channel_class = Type(InProcessChannel)
45 45 hb_channel_class = Type(InProcessHBChannel)
46 46
47 kernel = Instance('IPython.kernel.inprocess.ipkernel.InProcessKernel')
47 kernel = Instance('IPython.kernel.inprocess.ipkernel.InProcessKernel',
48 allow_none=True)
48 49
49 50 #--------------------------------------------------------------------------
50 51 # Channel management methods
@@ -27,7 +27,8 b' class InProcessKernel(IPythonKernel):'
27 27
28 28 # The frontends connected to this kernel.
29 29 frontends = List(
30 Instance('IPython.kernel.inprocess.client.InProcessKernelClient')
30 Instance('IPython.kernel.inprocess.client.InProcessKernelClient',
31 allow_none=True)
31 32 )
32 33
33 34 # The GUI environment that the kernel is running under. This need not be
@@ -45,7 +46,7 b' class InProcessKernel(IPythonKernel):'
45 46 # Kernel interface
46 47 #-------------------------------------------------------------------------
47 48
48 shell_class = Type()
49 shell_class = Type(allow_none=True)
49 50 shell_streams = List()
50 51 control_stream = Any()
51 52 iopub_socket = Instance(DummySocket, ())
@@ -140,7 +141,8 b' class InProcessKernel(IPythonKernel):'
140 141
141 142 class InProcessInteractiveShell(ZMQInteractiveShell):
142 143
143 kernel = Instance('IPython.kernel.inprocess.ipkernel.InProcessKernel')
144 kernel = Instance('IPython.kernel.inprocess.ipkernel.InProcessKernel',
145 allow_none=True)
144 146
145 147 #-------------------------------------------------------------------------
146 148 # InteractiveShell interface
@@ -20,7 +20,8 b' class InProcessKernelManager(KernelManager):'
20 20 """
21 21
22 22 # The kernel process with which the KernelManager is communicating.
23 kernel = Instance('IPython.kernel.inprocess.ipkernel.InProcessKernel')
23 kernel = Instance('IPython.kernel.inprocess.ipkernel.InProcessKernel',
24 allow_none=True)
24 25 # the client class for KM.client() shortcut
25 26 client_class = DottedObjectName('IPython.kernel.inprocess.BlockingInProcessKernelClient')
26 27
@@ -36,11 +36,11 b' def as_zmqstream(f):'
36 36
37 37 class IOLoopKernelManager(KernelManager):
38 38
39 loop = Instance('zmq.eventloop.ioloop.IOLoop', allow_none=False)
39 loop = Instance('zmq.eventloop.ioloop.IOLoop')
40 40 def _loop_default(self):
41 41 return ioloop.IOLoop.instance()
42 42
43 _restarter = Instance('IPython.kernel.ioloop.IOLoopKernelRestarter')
43 _restarter = Instance('IPython.kernel.ioloop.IOLoopKernelRestarter', allow_none=True)
44 44
45 45 def start_restarter(self):
46 46 if self.autorestart and self.has_kernel:
@@ -32,7 +32,7 b' from IPython.utils.traitlets import ('
32 32 class IOLoopKernelRestarter(KernelRestarter):
33 33 """Monitor and autorestart a kernel."""
34 34
35 loop = Instance('zmq.eventloop.ioloop.IOLoop', allow_none=False)
35 loop = Instance('zmq.eventloop.ioloop.IOLoop')
36 36 def _loop_default(self):
37 37 return ioloop.IOLoop.instance()
38 38
@@ -49,7 +49,7 b' class KernelManager(ConnectionFileMixin):'
49 49
50 50 # the class to create with our `client` method
51 51 client_class = DottedObjectName('IPython.kernel.blocking.BlockingKernelClient')
52 client_factory = Type()
52 client_factory = Type(allow_none=True)
53 53 def _client_class_changed(self, name, old, new):
54 54 self.client_factory = import_item(str(new))
55 55
@@ -27,8 +27,8 b' from IPython.kernel.zmq.session import Session, extract_header'
27 27 class ZMQDataPublisher(Configurable):
28 28
29 29 topic = topic = CBytes(b'datapub')
30 session = Instance(Session)
31 pub_socket = Instance(SocketABC)
30 session = Instance(Session, allow_none=True)
31 pub_socket = Instance(SocketABC, allow_none=True)
32 32 parent_header = Dict({})
33 33
34 34 def set_parent(self, parent):
@@ -42,8 +42,8 b' class ZMQShellDisplayHook(DisplayHook):'
42 42 representations of the object."""
43 43 topic=None
44 44
45 session = Instance(Session)
46 pub_socket = Instance(SocketABC)
45 session = Instance(Session, allow_none=True)
46 pub_socket = Instance(SocketABC, allow_none=True)
47 47 parent_header = Dict({})
48 48
49 49 def set_parent(self, parent):
@@ -22,7 +22,8 b' def lazy_import_handle_comm_opened(*args, **kwargs):'
22 22
23 23
24 24 class IPythonKernel(KernelBase):
25 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC')
25 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC',
26 allow_none=True)
26 27 shell_class = Type(ZMQInteractiveShell)
27 28
28 29 user_module = Any()
@@ -364,4 +365,4 b' class Kernel(IPythonKernel):'
364 365 import warnings
365 366 warnings.warn('Kernel is a deprecated alias of IPython.kernel.zmq.ipkernel.IPythonKernel',
366 367 DeprecationWarning)
367 super(Kernel, self).__init__(*args, **kwargs) No newline at end of file
368 super(Kernel, self).__init__(*args, **kwargs)
@@ -108,7 +108,7 b' class IPKernelApp(BaseIPythonApplication, InteractiveShellApp,'
108 108 """)
109 109 kernel = Any()
110 110 poller = Any() # don't restrict this even though current pollers are all Threads
111 heartbeat = Instance(Heartbeat)
111 heartbeat = Instance(Heartbeat, allow_none=True)
112 112 ports = Dict()
113 113
114 114 # connection info:
@@ -45,13 +45,13 b' class Kernel(SingletonConfigurable):'
45 45 loop = ioloop.IOLoop.instance()
46 46 loop.add_callback(self.enter_eventloop)
47 47
48 session = Instance(Session)
49 profile_dir = Instance('IPython.core.profiledir.ProfileDir')
48 session = Instance(Session, allow_none=True)
49 profile_dir = Instance('IPython.core.profiledir.ProfileDir', allow_none=True)
50 50 shell_streams = List()
51 control_stream = Instance(ZMQStream)
52 iopub_socket = Instance(zmq.Socket)
53 stdin_socket = Instance(zmq.Socket)
54 log = Instance(logging.Logger)
51 control_stream = Instance(ZMQStream, allow_none=True)
52 iopub_socket = Instance(zmq.Socket, allow_none=True)
53 stdin_socket = Instance(zmq.Socket, allow_none=True)
54 log = Instance(logging.Logger, allow_none=True)
55 55
56 56 # identities:
57 57 int_id = Integer(-1)
@@ -114,6 +114,7 b' class InlineBackend(InlineBackendConfig):'
114 114 be explicit.
115 115 """)
116 116
117 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC')
117 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC',
118 allow_none=True)
118 119
119 120
@@ -148,9 +148,10 b' class SessionFactory(LoggingConfigurable):'
148 148 def _context_default(self):
149 149 return zmq.Context.instance()
150 150
151 session = Instance('IPython.kernel.zmq.session.Session')
151 session = Instance('IPython.kernel.zmq.session.Session',
152 allow_none=True)
152 153
153 loop = Instance('zmq.eventloop.ioloop.IOLoop', allow_none=False)
154 loop = Instance('zmq.eventloop.ioloop.IOLoop')
154 155 def _loop_default(self):
155 156 return IOLoop.instance()
156 157
@@ -340,7 +341,7 b' class Session(Configurable):'
340 341 def _digest_mod_default(self):
341 342 return hashlib.sha256
342 343
343 auth = Instance(hmac.HMAC)
344 auth = Instance(hmac.HMAC, allow_none=True)
344 345
345 346 def _new_auth(self):
346 347 if self.key:
@@ -58,8 +58,8 b' from .session import Session'
58 58 class ZMQDisplayPublisher(DisplayPublisher):
59 59 """A display publisher that publishes data using a ZeroMQ PUB socket."""
60 60
61 session = Instance(Session)
62 pub_socket = Instance(SocketABC)
61 session = Instance(Session, allow_none=True)
62 pub_socket = Instance(SocketABC, allow_none=True)
63 63 parent_header = Dict({})
64 64 topic = CBytes(b'display_data')
65 65
@@ -445,7 +445,7 b' class TestType(TestCase):'
445 445
446 446 class B(object): pass
447 447 class A(HasTraits):
448 klass = Type
448 klass = Type(allow_none=True)
449 449
450 450 a = A()
451 451 self.assertEqual(a.klass, None)
@@ -472,7 +472,7 b' class TestType(TestCase):'
472 472 class B(object): pass
473 473 class C(B): pass
474 474 class A(HasTraits):
475 klass = Type(B, allow_none=False)
475 klass = Type(B)
476 476
477 477 a = A()
478 478 self.assertEqual(a.klass, B)
@@ -501,7 +501,7 b' class TestType(TestCase):'
501 501 self.assertRaises(ImportError, A)
502 502
503 503 class C(HasTraits):
504 klass = Type(None, B, allow_none=False)
504 klass = Type(None, B)
505 505
506 506 self.assertRaises(TraitError, C)
507 507
@@ -534,7 +534,7 b' class TestInstance(TestCase):'
534 534 class Bah(object): pass
535 535
536 536 class A(HasTraits):
537 inst = Instance(Foo)
537 inst = Instance(Foo, allow_none=True)
538 538
539 539 a = A()
540 540 self.assertTrue(a.inst is None)
@@ -555,7 +555,7 b' class TestInstance(TestCase):'
555 555 klass = Foo
556 556
557 557 class A(HasTraits):
558 inst = FooInstance()
558 inst = FooInstance(allow_none=True)
559 559
560 560 a = A()
561 561 self.assertTrue(a.inst is None)
@@ -596,7 +596,7 b' class TestInstance(TestCase):'
596 596 self.assertEqual(b.inst.d, 20)
597 597
598 598 class C(HasTraits):
599 inst = Instance(Foo)
599 inst = Instance(Foo, allow_none=True)
600 600 c = C()
601 601 self.assertTrue(c.inst is None)
602 602
@@ -604,7 +604,7 b' class TestInstance(TestCase):'
604 604 class Foo(object): pass
605 605
606 606 class A(HasTraits):
607 inst = Instance(Foo, allow_none=False)
607 inst = Instance(Foo)
608 608
609 609 self.assertRaises(TraitError, A)
610 610
@@ -951,7 +951,7 b' class Foo(object):'
951 951
952 952 class NoneInstanceListTrait(HasTraits):
953 953
954 value = List(Instance(Foo, allow_none=False))
954 value = List(Instance(Foo))
955 955
956 956 class TestNoneInstanceList(TraitTestBase):
957 957
@@ -975,7 +975,7 b' class TestInstanceList(TraitTestBase):'
975 975 self.assertIs(self.obj.traits()['value']._trait.klass, Foo)
976 976
977 977 _default_value = []
978 _good_values = [[Foo(), Foo(), None], []]
978 _good_values = [[Foo(), Foo()], []]
979 979 _bad_values = [['1', 2,], '1', [Foo], None]
980 980
981 981 class UnionListTrait(HasTraits):
@@ -1120,7 +1120,7 b' class TestValidationHook(TestCase):'
1120 1120 class Parity(HasTraits):
1121 1121
1122 1122 value = Int(0)
1123 parity = Enum(['odd', 'even'], default_value='even', allow_none=False)
1123 parity = Enum(['odd', 'even'], default_value='even')
1124 1124
1125 1125 def _value_validate(self, value, trait):
1126 1126 if self.parity == 'even' and value % 2:
@@ -1469,11 +1469,11 b' class TestEventful(TestCase):'
1469 1469 ###
1470 1470 class ForwardDeclaredInstanceTrait(HasTraits):
1471 1471
1472 value = ForwardDeclaredInstance('ForwardDeclaredBar')
1472 value = ForwardDeclaredInstance('ForwardDeclaredBar', allow_none=True)
1473 1473
1474 1474 class ForwardDeclaredTypeTrait(HasTraits):
1475 1475
1476 value = ForwardDeclaredType('ForwardDeclaredBar')
1476 value = ForwardDeclaredType('ForwardDeclaredBar', allow_none=True)
1477 1477
1478 1478 class ForwardDeclaredInstanceListTrait(HasTraits):
1479 1479
@@ -1525,16 +1525,16 b' class TestForwardDeclaredInstanceList(TraitTestBase):'
1525 1525
1526 1526 _default_value = []
1527 1527 _good_values = [
1528 [ForwardDeclaredBar(), ForwardDeclaredBarSub(), None],
1529 [None],
1528 [ForwardDeclaredBar(), ForwardDeclaredBarSub()],
1530 1529 [],
1531 1530 ]
1532 1531 _bad_values = [
1533 1532 ForwardDeclaredBar(),
1534 [ForwardDeclaredBar(), 3],
1533 [ForwardDeclaredBar(), 3, None],
1535 1534 '1',
1536 1535 # Note that this is the type, not an instance.
1537 1536 [ForwardDeclaredBar],
1537 [None],
1538 1538 None,
1539 1539 ]
1540 1540
@@ -1548,9 +1548,8 b' class TestForwardDeclaredTypeList(TraitTestBase):'
1548 1548
1549 1549 _default_value = []
1550 1550 _good_values = [
1551 [ForwardDeclaredBar, ForwardDeclaredBarSub, None],
1551 [ForwardDeclaredBar, ForwardDeclaredBarSub],
1552 1552 [],
1553 [None],
1554 1553 ]
1555 1554 _bad_values = [
1556 1555 ForwardDeclaredBar,
@@ -1558,6 +1557,7 b' class TestForwardDeclaredTypeList(TraitTestBase):'
1558 1557 '1',
1559 1558 # Note that this is an instance, not the type.
1560 1559 [ForwardDeclaredBar()],
1560 [None],
1561 1561 None,
1562 1562 ]
1563 1563 ###
@@ -852,7 +852,8 b' class ClassBasedTraitType(TraitType):'
852 852 class Type(ClassBasedTraitType):
853 853 """A trait whose value must be a subclass of a specified class."""
854 854
855 def __init__ (self, default_value=None, klass=None, allow_none=True, **metadata ):
855 def __init__ (self, default_value=None, klass=None, allow_none=False,
856 **metadata):
856 857 """Construct a Type trait
857 858
858 859 A Type trait specifies that its values must be subclasses of
@@ -952,8 +953,8 b' class Instance(ClassBasedTraitType):'
952 953
953 954 klass = None
954 955
955 def __init__(self, klass=None, args=None, kw=None,
956 allow_none=True, **metadata ):
956 def __init__(self, klass=None, args=None, kw=None, allow_none=False,
957 **metadata ):
957 958 """Construct an Instance trait.
958 959
959 960 This trait allows values that are instances of a particular
@@ -1656,7 +1657,7 b' class Tuple(Container):'
1656 1657 if self._traits and default_value is None:
1657 1658 # don't allow default to be an empty container if length is specified
1658 1659 args = None
1659 super(Container,self).__init__(klass=self.klass, args=args, **metadata)
1660 super(Container,self).__init__(klass=self.klass, args=args, allow_none=allow_none, **metadata)
1660 1661
1661 1662 def validate_elements(self, obj, value):
1662 1663 if not self._traits:
@@ -174,7 +174,7 b' class IPEngineApp(BaseParallelApplication):'
174 174 logging to a central location.""")
175 175
176 176 # an IPKernelApp instance, used to setup listening for shell frontends
177 kernel_app = Instance(IPKernelApp)
177 kernel_app = Instance(IPKernelApp, allow_none=True)
178 178
179 179 aliases = Dict(aliases)
180 180 flags = Dict(flags)
@@ -102,7 +102,7 b' class BaseLauncher(LoggingConfigurable):'
102 102 # controller_args, engine_args attributes of the launchers to add
103 103 # the work_dir option.
104 104 work_dir = Unicode(u'.')
105 loop = Instance('zmq.eventloop.ioloop.IOLoop')
105 loop = Instance('zmq.eventloop.ioloop.IOLoop', allow_none=True)
106 106
107 107 start_data = Any()
108 108 stop_data = Any()
@@ -50,7 +50,7 b' class LogWatcher(LoggingConfigurable):'
50 50 return 'tcp://%s:20202' % localhost()
51 51
52 52 # internals
53 stream = Instance('zmq.eventloop.zmqstream.ZMQStream')
53 stream = Instance('zmq.eventloop.zmqstream.ZMQStream', allow_none=True)
54 54
55 55 context = Instance(zmq.Context)
56 56 def _context_default(self):
@@ -107,7 +107,7 b' class View(HasTraits):'
107 107 history=List()
108 108 outstanding = Set()
109 109 results = Dict()
110 client = Instance('ipython_parallel.Client')
110 client = Instance('ipython_parallel.Client', allow_none=True)
111 111
112 112 _socket = Instance('zmq.Socket')
113 113 _flag_names = List(['targets', 'block', 'track'])
@@ -215,7 +215,7 b' class View(HasTraits):'
215 215
216 216 This method sets all apply flags via this View's attributes.
217 217
218 Returns :class:`~ipython_parallel.client.asyncresult.AsyncResult`
218 Returns :class:`~IPython.parallel.client.asyncresult.AsyncResult`
219 219 instance if ``self.block`` is False, otherwise the return value of
220 220 ``f(*args, **kwargs)``.
221 221 """
@@ -224,7 +224,7 b' class View(HasTraits):'
224 224 def apply_async(self, f, *args, **kwargs):
225 225 """calls ``f(*args, **kwargs)`` on remote engines in a nonblocking manner.
226 226
227 Returns :class:`~ipython_parallel.client.asyncresult.AsyncResult` instance.
227 Returns :class:`~IPython.parallel.client.asyncresult.AsyncResult` instance.
228 228 """
229 229 return self._really_apply(f, args, kwargs, block=False)
230 230
@@ -307,7 +307,7 b' class View(HasTraits):'
307 307 def get_result(self, indices_or_msg_ids=None, block=None, owner=True):
308 308 """return one or more results, specified by history index or msg_id.
309 309
310 See :meth:`ipython_parallel.client.client.Client.get_result` for details.
310 See :meth:`IPython.parallel.client.client.Client.get_result` for details.
311 311 """
312 312
313 313 if indices_or_msg_ids is None:
@@ -832,7 +832,7 b' class DirectView(View):'
832 832 on the even engines.
833 833 """
834 834
835 from ipython_parallel.client.magics import ParallelMagics
835 from IPython.parallel.client.magics import ParallelMagics
836 836
837 837 try:
838 838 # This is injected into __builtins__.
@@ -77,8 +77,8 b' class HeartMonitor(LoggingConfigurable):'
77 77 help='Allowed consecutive missed pings from controller Hub to engine before unregistering.',
78 78 )
79 79
80 pingstream=Instance('zmq.eventloop.zmqstream.ZMQStream')
81 pongstream=Instance('zmq.eventloop.zmqstream.ZMQStream')
80 pingstream=Instance('zmq.eventloop.zmqstream.ZMQStream', allow_none=True)
81 pongstream=Instance('zmq.eventloop.zmqstream.ZMQStream', allow_none=True)
82 82 loop = Instance('zmq.eventloop.ioloop.IOLoop')
83 83 def _loop_default(self):
84 84 return ioloop.IOLoop.instance()
@@ -211,8 +211,8 b' class HubFactory(RegistrationFactory):'
211 211 return max(30, int(.01 * self.heartmonitor.period))
212 212
213 213 # not configurable
214 db = Instance('ipython_parallel.controller.dictdb.BaseDB')
215 heartmonitor = Instance('ipython_parallel.controller.heartmonitor.HeartMonitor')
214 db = Instance('ipython_parallel.controller.dictdb.BaseDB', allow_none=True)
215 heartmonitor = Instance('ipython_parallel.controller.heartmonitor.HeartMonitor', allow_none=True)
216 216
217 217 def _ip_changed(self, name, old, new):
218 218 self.engine_ip = new
@@ -382,12 +382,12 b' class Hub(SessionFactory):'
382 382 _idcounter=Integer(0)
383 383
384 384 # objects from constructor:
385 query=Instance(ZMQStream)
386 monitor=Instance(ZMQStream)
387 notifier=Instance(ZMQStream)
388 resubmit=Instance(ZMQStream)
389 heartmonitor=Instance(HeartMonitor)
390 db=Instance(object)
385 query=Instance(ZMQStream, allow_none=True)
386 monitor=Instance(ZMQStream, allow_none=True)
387 notifier=Instance(ZMQStream, allow_none=True)
388 resubmit=Instance(ZMQStream, allow_none=True)
389 heartmonitor=Instance(HeartMonitor, allow_none=True)
390 db=Instance(object, allow_none=True)
391 391 client_info=Dict()
392 392 engine_info=Dict()
393 393
@@ -45,7 +45,7 b' class MongoDB(BaseDB):'
45 45 in tasks from previous sessions being available via Clients' db_query and
46 46 get_result methods.""")
47 47
48 _connection = Instance(Connection) # pymongo connection
48 _connection = Instance(Connection, allow_none=True) # pymongo connection
49 49
50 50 def __init__(self, **kwargs):
51 51 super(MongoDB, self).__init__(**kwargs)
@@ -183,11 +183,11 b' help="""select the task scheduler scheme [default: Python LRU]'
183 183 scheme = Instance(FunctionType) # function for determining the destination
184 184 def _scheme_default(self):
185 185 return leastload
186 client_stream = Instance(zmqstream.ZMQStream) # client-facing stream
187 engine_stream = Instance(zmqstream.ZMQStream) # engine-facing stream
188 notifier_stream = Instance(zmqstream.ZMQStream) # hub-facing sub stream
189 mon_stream = Instance(zmqstream.ZMQStream) # hub-facing pub stream
190 query_stream = Instance(zmqstream.ZMQStream) # hub-facing DEALER stream
186 client_stream = Instance(zmqstream.ZMQStream, allow_none=True) # client-facing stream
187 engine_stream = Instance(zmqstream.ZMQStream, allow_none=True) # engine-facing stream
188 notifier_stream = Instance(zmqstream.ZMQStream, allow_none=True) # hub-facing sub stream
189 mon_stream = Instance(zmqstream.ZMQStream, allow_none=True) # hub-facing pub stream
190 query_stream = Instance(zmqstream.ZMQStream, allow_none=True) # hub-facing DEALER stream
191 191
192 192 # internals:
193 193 queue = Instance(deque) # sorted list of Jobs
@@ -99,7 +99,7 b' class SQLiteDB(BaseDB):'
99 99 get_result methods.""")
100 100
101 101 if sqlite3 is not None:
102 _db = Instance('sqlite3.Connection')
102 _db = Instance('sqlite3.Connection', allow_none=True)
103 103 else:
104 104 _db = None
105 105 # the ordered list of column names
@@ -411,4 +411,4 b' class SQLiteDB(BaseDB):'
411 411 # will be a list of length 1 tuples
412 412 return [ tup[0] for tup in cursor.fetchall()]
413 413
414 __all__ = ['SQLiteDB'] No newline at end of file
414 __all__ = ['SQLiteDB']
@@ -67,8 +67,8 b' class EngineFactory(RegistrationFactory):'
67 67 connection_info = Dict()
68 68 user_ns = Dict()
69 69 id = Integer(allow_none=True)
70 registrar = Instance('zmq.eventloop.zmqstream.ZMQStream')
71 kernel = Instance(Kernel)
70 registrar = Instance('zmq.eventloop.zmqstream.ZMQStream', allow_none=True)
71 kernel = Instance(Kernel, allow_none=True)
72 72 hb_check_period=Integer()
73 73
74 74 # States for the heartbeat monitoring
@@ -109,8 +109,8 b' class ZMQTerminalInteractiveShell(TerminalInteractiveShell):'
109 109 """
110 110 )
111 111
112 manager = Instance('IPython.kernel.KernelManager')
113 client = Instance('IPython.kernel.KernelClient')
112 manager = Instance('IPython.kernel.KernelManager', allow_none=True)
113 client = Instance('IPython.kernel.KernelClient', allow_none=True)
114 114 def _client_changed(self, name, old, new):
115 115 self.session_id = new.session.session
116 116 session_id = Unicode()
@@ -161,14 +161,14 b' class NbConvertApp(BaseIPythonApplication):'
161 161 # Writer specific variables
162 162 writer = Instance('jupyter_nbconvert.writers.base.WriterBase',
163 163 help="""Instance of the writer class used to write the
164 results of the conversion.""")
164 results of the conversion.""", allow_none=True)
165 165 writer_class = DottedObjectName('FilesWriter', config=True,
166 166 help="""Writer class used to write the
167 167 results of the conversion""")
168 168 writer_aliases = {'fileswriter': 'jupyter_nbconvert.writers.files.FilesWriter',
169 169 'debugwriter': 'jupyter_nbconvert.writers.debug.DebugWriter',
170 170 'stdoutwriter': 'jupyter_nbconvert.writers.stdout.StdoutWriter'}
171 writer_factory = Type()
171 writer_factory = Type(allow_none=True)
172 172
173 173 def _writer_class_changed(self, name, old, new):
174 174 if new.lower() in self.writer_aliases:
@@ -178,13 +178,13 b' class NbConvertApp(BaseIPythonApplication):'
178 178 # Post-processor specific variables
179 179 postprocessor = Instance('jupyter_nbconvert.postprocessors.base.PostProcessorBase',
180 180 help="""Instance of the PostProcessor class used to write the
181 results of the conversion.""")
181 results of the conversion.""", allow_none=True)
182 182
183 183 postprocessor_class = DottedOrNone(config=True,
184 184 help="""PostProcessor class used to write the
185 185 results of the conversion""")
186 186 postprocessor_aliases = {'serve': 'jupyter_nbconvert.postprocessors.serve.ServePostProcessor'}
187 postprocessor_factory = Type()
187 postprocessor_factory = Type(allow_none=True)
188 188
189 189 def _postprocessor_class_changed(self, name, old, new):
190 190 if new.lower() in self.postprocessor_aliases:
@@ -87,7 +87,7 b' def signature_removed(nb):'
87 87 class NotebookNotary(LoggingConfigurable):
88 88 """A class for computing and verifying notebook signatures."""
89 89
90 profile_dir = Instance("IPython.core.profiledir.ProfileDir")
90 profile_dir = Instance("IPython.core.profiledir.ProfileDir", allow_none=True)
91 91 def _profile_dir_default(self):
92 92 from IPython.core.application import BaseIPythonApplication
93 93 app = None
@@ -145,7 +145,7 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
145 145 _ExecutionRequest = namedtuple('_ExecutionRequest', ['id', 'kind'])
146 146 _input_splitter_class = InputSplitter
147 147 _local_kernel = False
148 _highlighter = Instance(FrontendHighlighter)
148 _highlighter = Instance(FrontendHighlighter, allow_none=True)
149 149
150 150 #---------------------------------------------------------------------------
151 151 # 'object' interface
General Comments 0
You need to be logged in to leave comments. Login now