Skip to content

Commit 682b208

Browse files
committed
Add Callable traitlet
1 parent 8df8666 commit 682b208

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

jupyter_server_proxy/config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22
Traitlets based configuration for jupyter_server_proxy
33
"""
44
from notebook.utils import url_path_join as ujoin
5-
from traitlets import Callable, Dict, List, Union
5+
from traitlets import Dict, List, Union
66
from traitlets.config import Configurable
77
from .handlers import SuperviseAndProxyHandler, AddSlashHandler
88
import pkg_resources
99
from collections import namedtuple
1010
from .utils import call_with_asked_args
1111

12+
try:
13+
# Traitlets >= 4.3.3
14+
from traitlets import Callable
15+
except ImportError:
16+
from .utils import Callable
17+
1218
def _make_serverproxy_handler(name, command, environment, timeout, absolute_url, port):
1319
"""
1420
Create a SuperviseAndProxyHandler subclass with given parameters

jupyter_server_proxy/utils.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from traitlets import TraitType
2+
import six
3+
14
def call_with_asked_args(callback, args):
25
"""
36
Call callback with only the args it wants from args
@@ -29,3 +32,19 @@ def call_with_asked_args(callback, args):
2932
)
3033
)
3134
return callback(*asked_arg_values)
35+
36+
# copy-pasted from the master of Traitlets source
37+
class Callable(TraitType):
38+
"""A trait which is callable.
39+
Notes
40+
-----
41+
Classes are callable, as are instances
42+
with a __call__() method."""
43+
44+
info_text = 'a callable'
45+
46+
def validate(self, obj, value):
47+
if six.callable(value):
48+
return value
49+
else:
50+
self.error(obj, value)

0 commit comments

Comments
 (0)