Skip to content

Commit 84df529

Browse files
author
Sai Rahul Poruri
committed
CLN : Update super usage
This commit updates the super usage. Because Python 2 is not supported anymore, super usage can be updated such that super is called without any arguments in the default case where super is called with the class name and self. Note that all usage of super has not been updated - a few cases which smelled funny have been ignored.
1 parent 2ba2960 commit 84df529

19 files changed

+56
-60
lines changed

notebook/base/handlers.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def allow_credentials(self):
301301

302302
def set_default_headers(self):
303303
"""Add CORS headers, if defined"""
304-
super(IPythonHandler, self).set_default_headers()
304+
super().set_default_headers()
305305
if self.allow_origin:
306306
self.set_header("Access-Control-Allow-Origin", self.allow_origin)
307307
elif self.allow_origin_pat:
@@ -442,7 +442,7 @@ def check_xsrf_cookie(self):
442442
# Servers without authentication are vulnerable to XSRF
443443
return
444444
try:
445-
return super(IPythonHandler, self).check_xsrf_cookie()
445+
return super().check_xsrf_cookie()
446446
except web.HTTPError as e:
447447
if self.request.method in {'GET', 'HEAD'}:
448448
# Consider Referer a sufficient cross-origin check for GET requests
@@ -496,7 +496,7 @@ def check_host(self):
496496
def prepare(self):
497497
if not self.check_host():
498498
raise web.HTTPError(403)
499-
return super(IPythonHandler, self).prepare()
499+
return super().prepare()
500500

501501
#---------------------------------------------------------------
502502
# template rendering
@@ -591,7 +591,7 @@ class APIHandler(IPythonHandler):
591591
def prepare(self):
592592
if not self.check_origin():
593593
raise web.HTTPError(404)
594-
return super(APIHandler, self).prepare()
594+
return super().prepare()
595595

596596
def write_error(self, status_code, **kwargs):
597597
"""APIHandler errors are JSON, not human pages"""
@@ -618,7 +618,7 @@ def get_current_user(self):
618618
# preserve _user_cache so we don't raise more than once
619619
if hasattr(self, '_user_cache'):
620620
return self._user_cache
621-
self._user_cache = user = super(APIHandler, self).get_current_user()
621+
self._user_cache = user = super().get_current_user()
622622
return user
623623

624624
def get_login_url(self):
@@ -627,12 +627,12 @@ def get_login_url(self):
627627
# instead of redirecting, raise 403 instead.
628628
if not self.current_user:
629629
raise web.HTTPError(403)
630-
return super(APIHandler, self).get_login_url()
630+
return super().get_login_url()
631631

632632
@property
633633
def content_security_policy(self):
634634
csp = '; '.join([
635-
super(APIHandler, self).content_security_policy,
635+
super().content_security_policy,
636636
"default-src 'none'",
637637
])
638638
return csp
@@ -653,7 +653,7 @@ def update_api_activity(self):
653653
def finish(self, *args, **kwargs):
654654
self.update_api_activity()
655655
self.set_header('Content-Type', 'application/json')
656-
return super(APIHandler, self).finish(*args, **kwargs)
656+
return super().finish(*args, **kwargs)
657657

658658
def options(self, *args, **kwargs):
659659
if 'Access-Control-Allow-Headers' in self.settings.get('headers', {}):
@@ -700,13 +700,12 @@ class AuthenticatedFileHandler(IPythonHandler, web.StaticFileHandler):
700700
def content_security_policy(self):
701701
# In case we're serving HTML/SVG, confine any Javascript to a unique
702702
# origin so it can't interact with the notebook server.
703-
return super(AuthenticatedFileHandler, self).content_security_policy + \
704-
"; sandbox allow-scripts"
703+
return super().content_security_policy + "; sandbox allow-scripts"
705704

706705
@web.authenticated
707706
def head(self, path):
708707
self.check_xsrf_cookie()
709-
return super(AuthenticatedFileHandler, self).head(path)
708+
return super().head(path)
710709

711710
@web.authenticated
712711
def get(self, path):
@@ -731,10 +730,10 @@ def get_content_type(self):
731730
if cur_mime == 'text/plain':
732731
return 'text/plain; charset=UTF-8'
733732
else:
734-
return super(AuthenticatedFileHandler, self).get_content_type()
733+
return super().get_content_type()
735734

736735
def set_headers(self):
737-
super(AuthenticatedFileHandler, self).set_headers()
736+
super().set_headers()
738737
# disable browser caching, rely on 304 replies for savings
739738
if "v" not in self.request.arguments:
740739
self.add_header("Cache-Control", "no-cache")
@@ -749,7 +748,7 @@ def validate_absolute_path(self, root, absolute_path):
749748
750749
Adding to tornado's own handling, forbids the serving of hidden files.
751750
"""
752-
abs_path = super(AuthenticatedFileHandler, self).validate_absolute_path(root, absolute_path)
751+
abs_path = super().validate_absolute_path(root, absolute_path)
753752
abs_root = os.path.abspath(root)
754753
if is_hidden(abs_path, abs_root) and not self.contents_manager.allow_hidden:
755754
self.log.info("Refusing to serve hidden file, via 404 Error, use flag 'ContentsManager.allow_hidden' to enable")
@@ -795,7 +794,7 @@ class FileFindHandler(IPythonHandler, web.StaticFileHandler):
795794
_static_paths = {}
796795

797796
def set_headers(self):
798-
super(FileFindHandler, self).set_headers()
797+
super().set_headers()
799798
# disable browser caching, rely on 304 replies for savings
800799
if "v" not in self.request.arguments or \
801800
any(self.request.path.startswith(path) for path in self.no_cache_paths):
@@ -842,7 +841,7 @@ def validate_absolute_path(self, root, absolute_path):
842841
if (absolute_path + os.sep).startswith(root):
843842
break
844843

845-
return super(FileFindHandler, self).validate_absolute_path(root, absolute_path)
844+
return super().validate_absolute_path(root, absolute_path)
846845

847846

848847
class APIVersionHandler(APIHandler):

notebook/base/zmqhandlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def get(self, *args, **kwargs):
289289
# assign and yield in two step to avoid tornado 3 issues
290290
res = self.pre_get()
291291
yield maybe_future(res)
292-
res = super(AuthenticatedZMQStreamHandler, self).get(*args, **kwargs)
292+
res = super().get(*args, **kwargs)
293293
yield maybe_future(res)
294294

295295
def initialize(self):

notebook/bundler/bundlerextensions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ class BundlerExtensionApp(BaseExtensionApp):
294294

295295
def start(self):
296296
"""Perform the App's functions as configured"""
297-
super(BundlerExtensionApp, self).start()
297+
super().start()
298298

299299
# The above should have called a subcommand and raised NoStart; if we
300300
# get here, it didn't, so we should self.log.info a message.

notebook/files/handlers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ class FilesHandler(IPythonHandler):
2626
def content_security_policy(self):
2727
# In case we're serving HTML/SVG, confine any Javascript to a unique
2828
# origin so it can't interact with the notebook server.
29-
return super(FilesHandler, self).content_security_policy + \
30-
"; sandbox allow-scripts"
29+
return super().content_security_policy + "; sandbox allow-scripts"
3130

3231
@web.authenticated
3332
def head(self, path):

notebook/gateway/handlers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def initialize(self):
6868
def get(self, kernel_id, *args, **kwargs):
6969
self.authenticate()
7070
self.kernel_id = cast_unicode(kernel_id, 'ascii')
71-
yield super(WebSocketChannelsHandler, self).get(kernel_id=kernel_id, *args, **kwargs)
71+
yield super().get(kernel_id=kernel_id, *args, **kwargs)
7272

7373
def send_ping(self):
7474
if self.ws_connection is None and self.ping_callback is not None:
@@ -97,15 +97,15 @@ def write_message(self, message, binary=False):
9797
if self.ws_connection: # prevent WebSocketClosedError
9898
if isinstance(message, bytes):
9999
binary = True
100-
super(WebSocketChannelsHandler, self).write_message(message, binary=binary)
100+
super().write_message(message, binary=binary)
101101
elif self.log.isEnabledFor(logging.DEBUG):
102102
msg_summary = WebSocketChannelsHandler._get_message_summary(json_decode(utf8(message)))
103103
self.log.debug("Notebook client closed websocket connection - message dropped: {}".format(msg_summary))
104104

105105
def on_close(self):
106106
self.log.debug("Closing websocket connection %s", self.request.path)
107107
self.gateway.on_close()
108-
super(WebSocketChannelsHandler, self).on_close()
108+
super().on_close()
109109

110110
@staticmethod
111111
def _get_message_summary(message):
@@ -129,7 +129,7 @@ class GatewayWebSocketClient(LoggingConfigurable):
129129
"""Proxy web socket connection to a kernel/enterprise gateway."""
130130

131131
def __init__(self, **kwargs):
132-
super(GatewayWebSocketClient, self).__init__(**kwargs)
132+
super().__init__(**kwargs)
133133
self.kernel_id = None
134134
self.ws = None
135135
self.ws_future = Future()

notebook/gateway/managers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def validate_cert_default(self):
205205
return bool(os.environ.get(self.validate_cert_env, str(self.validate_cert_default_value)) not in ['no', 'false'])
206206

207207
def __init__(self, **kwargs):
208-
super(GatewayClient, self).__init__(**kwargs)
208+
super().__init__(**kwargs)
209209
self._static_args = {} # initialized on first use
210210

211211
env_whitelist_default_value = ''
@@ -310,7 +310,7 @@ class GatewayKernelManager(MappingKernelManager):
310310
_kernels = {}
311311

312312
def __init__(self, **kwargs):
313-
super(GatewayKernelManager, self).__init__(**kwargs)
313+
super().__init__(**kwargs)
314314
self.base_endpoint = url_path_join(GatewayClient.instance().url, GatewayClient.instance().kernels_endpoint)
315315

316316
def __contains__(self, kernel_id):
@@ -507,7 +507,7 @@ def shutdown_all(self, now=False):
507507
class GatewayKernelSpecManager(KernelSpecManager):
508508

509509
def __init__(self, **kwargs):
510-
super(GatewayKernelSpecManager, self).__init__(**kwargs)
510+
super().__init__(**kwargs)
511511
base_endpoint = url_path_join(GatewayClient.instance().url,
512512
GatewayClient.instance().kernelspecs_endpoint)
513513

notebook/jstest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class StreamCapturer(Thread):
4545
daemon = True # Don't hang if main thread crashes
4646
started = False
4747
def __init__(self, echo=False):
48-
super(StreamCapturer, self).__init__()
48+
super().__init__()
4949
self.echo = echo
5050
self.streams = []
5151
self.buffer = BytesIO()
@@ -264,14 +264,14 @@ def launch(self, buffer_output):
264264
# If the engine is SlimerJS, we need to buffer the output because
265265
# SlimerJS does not support exit codes, so CasperJS always returns 0.
266266
if self.engine == 'slimerjs' and not buffer_output:
267-
return super(JSController, self).launch(capture_output=True)
267+
return super().launch(capture_output=True)
268268

269269
else:
270-
return super(JSController, self).launch(buffer_output=buffer_output)
270+
return super().launch(buffer_output=buffer_output)
271271

272272
def wait(self, *pargs, **kwargs):
273273
"""Wait for the JSController to finish"""
274-
ret = super(JSController, self).wait(*pargs, **kwargs)
274+
ret = super().wait(*pargs, **kwargs)
275275
# If this is a SlimerJS controller, check the captured stdout for
276276
# errors. Otherwise, just return the return code.
277277
if self.engine == 'slimerjs':

notebook/nbconvert/handlers.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ class NbconvertFileHandler(IPythonHandler):
8383
def content_security_policy(self):
8484
# In case we're serving HTML/SVG, confine any Javascript to a unique
8585
# origin so it can't interact with the notebook server.
86-
return super(NbconvertFileHandler, self).content_security_policy + \
87-
"; sandbox allow-scripts"
86+
return super().content_security_policy + "; sandbox allow-scripts"
8887

8988
@web.authenticated
9089
@gen.coroutine
@@ -158,8 +157,7 @@ class NbconvertPostHandler(IPythonHandler):
158157
def content_security_policy(self):
159158
# In case we're serving HTML/SVG, confine any Javascript to a unique
160159
# origin so it can't interact with the notebook server.
161-
return super(NbconvertPostHandler, self).content_security_policy + \
162-
"; sandbox allow-scripts"
160+
return super().content_security_policy + "; sandbox allow-scripts"
163161

164162
@web.authenticated
165163
def post(self, format):

notebook/nbextensions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ class NBExtensionApp(BaseExtensionApp):
980980

981981
def start(self):
982982
"""Perform the App's functions as configured"""
983-
super(NBExtensionApp, self).start()
983+
super().start()
984984

985985
# The above should have called a subcommand and raised NoStart; if we
986986
# get here, it didn't, so we should self.log.info a message.

notebook/notebookapp.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def __init__(self, jupyter_app, kernel_manager, contents_manager,
190190
if settings['autoreload']:
191191
log.info('Autoreload enabled: the webapp will restart when any Python src file changes.')
192192

193-
super(NotebookWebApplication, self).__init__(handlers, **settings)
193+
super().__init__(handlers, **settings)
194194

195195
def init_settings(self, jupyter_app, kernel_manager, contents_manager,
196196
session_manager, kernel_spec_manager,
@@ -511,7 +511,7 @@ class NbserverStopApp(JupyterApp):
511511
help="UNIX socket of the server to be killed.")
512512

513513
def parse_command_line(self, argv=None):
514-
super(NbserverStopApp, self).parse_command_line(argv)
514+
super().parse_command_line(argv)
515515
if self.extra_args:
516516
try:
517517
self.port = int(self.extra_args[0])
@@ -1523,7 +1523,7 @@ def _update_server_extensions(self, change):
15231523
terminals_available = False
15241524

15251525
def parse_command_line(self, argv=None):
1526-
super(NotebookApp, self).parse_command_line(argv)
1526+
super().parse_command_line(argv)
15271527

15281528
if self.extra_args:
15291529
arg0 = self.extra_args[0]
@@ -2026,7 +2026,7 @@ def _init_asyncio_patch(self):
20262026
def initialize(self, argv=None):
20272027
self._init_asyncio_patch()
20282028

2029-
super(NotebookApp, self).initialize(argv)
2029+
super().initialize(argv)
20302030
self.init_logging()
20312031
if self._dispatching:
20322032
return
@@ -2192,7 +2192,7 @@ def start(self):
21922192
This method takes no arguments so all configuration and initialization
21932193
must be done prior to calling this method."""
21942194

2195-
super(NotebookApp, self).start()
2195+
super().start()
21962196

21972197
if not self.allow_root:
21982198
# check if we are running as root, and abort if it's not allowed

0 commit comments

Comments
 (0)