Skip to content

Commit 204bc17

Browse files
committed
Modified repl.py to conform to follow more PEP standards including 8 and 263
1 parent a40c863 commit 204bc17

File tree

1 file changed

+41
-37
lines changed

1 file changed

+41
-37
lines changed

bpython/repl.py

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
1-
# encoding: utf-8
2-
3-
# The MIT License
4-
#
5-
# Copyright (c) 2009-2011 the bpython authors.
6-
# Copyright (c) 2012-2013,2015 Sebastian Ramacher
7-
#
8-
# Permission is hereby granted, free of charge, to any person obtaining a copy
9-
# of this software and associated documentation files (the "Software"), to deal
10-
# in the Software without restriction, including without limitation the rights
11-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12-
# copies of the Software, and to permit persons to whom the Software is
13-
# furnished to do so, subject to the following conditions:
14-
#
15-
# The above copyright notice and this permission notice shall be included in
16-
# all copies or substantial portions of the Software.
17-
#
18-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24-
# THE SOFTWARE.
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
The MIT License
5+
6+
Copyright (c) 2009-2011 the bpython authors.
7+
Copyright (c) 2012-2013,2015 Sebastian Ramacher
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a copy
10+
of this software and associated documentation files (the "Software"), to deal
11+
in the Software without restriction, including without limitation the rights
12+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
copies of the Software, and to permit persons to whom the Software is
14+
furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included in
17+
all copies or substantial portions of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
THE SOFTWARE.
26+
"""
2527

2628
import code
2729
import inspect
@@ -56,6 +58,7 @@
5658

5759

5860
class RuntimeTimer(object):
61+
"""Calculate running time"""
5962
def __init__(self):
6063
self.reset_timer()
6164
self.time = time.monotonic if hasattr(time, 'monotonic') else time.time
@@ -207,7 +210,7 @@ def showtraceback(self):
207210
tblist[i] = (fname, lineno, module, something)
208211
# Set the right lineno (encoding header adds an extra line)
209212
if fname == '<input>' and not py3:
210-
tblist[i] = (fname, lineno - 2, module, something)
213+
tblist[i] = (fname, lineno - 2, module, something)
211214

212215
l = traceback.format_list(tblist)
213216
if l:
@@ -601,7 +604,7 @@ def get_args(self):
601604
try:
602605
fake_cursor = self.current_line.index(func) + len(func)
603606
f = simpleeval.evaluate_current_attribute(
604-
fake_cursor, self.current_line, self.interp.locals)
607+
fake_cursor, self.current_line, self.interp.locals)
605608
except simpleeval.EvaluationError:
606609
return False
607610
except Exception:
@@ -770,13 +773,13 @@ def line_is_empty(line):
770773
indentation = 0
771774
return indentation
772775

773-
def formatforfile(self, s):
776+
def formatforfile(self, stdout):
774777
"""Format the stdout buffer to something suitable for writing to disk,
775778
i.e. without >>> and ... at input lines and with "# OUT: " prepended to
776779
output lines."""
777780

778781
def process():
779-
for line in s.split('\n'):
782+
for line in stdout.split('\n'):
780783
if line.startswith(self.ps1):
781784
yield line[len(self.ps1):]
782785
elif line.startswith(self.ps2):
@@ -817,11 +820,11 @@ def write2file(self):
817820
self.interact.notify(_('Save cancelled.'))
818821
return
819822

820-
s = self.formatforfile(self.getstdout())
823+
stdout_text = self.formatforfile(self.getstdout())
821824

822825
try:
823826
with open(fn, mode) as f:
824-
f.write(s)
827+
f.write(stdout_text)
825828
except IOError as e:
826829
self.interact.notify(_("Error writing file '%s': %s") % (fn, e))
827830
else:
@@ -859,8 +862,8 @@ def do_pastebin(self, s):
859862
if s == self.prev_pastebin_content:
860863
self.interact.notify(_('Duplicate pastebin. Previous URL: %s. '
861864
'Removal URL: %s') %
862-
(self.prev_pastebin_url,
863-
self.prev_removal_url), 10)
865+
(self.prev_pastebin_url,
866+
self.prev_removal_url), 10)
864867
return self.prev_pastebin_url
865868

866869
self.interact.notify(_('Posting data to pastebin...'))
@@ -1069,8 +1072,9 @@ def tokenize(self, s, newline=False):
10691072
def clear_current_line(self):
10701073
"""This is used as the exception callback for the Interpreter instance.
10711074
It prevents autoindentation from occurring after a traceback."""
1075+
# XXX: Empty function
10721076

1073-
def send_to_external_editor(self, text, filename=None):
1077+
def send_to_external_editor(self, text):
10741078
"""Returns modified text from an editor, or the original text if editor
10751079
exited with non-zero"""
10761080

@@ -1099,15 +1103,15 @@ def open_in_external_editor(self, filename):
10991103
return subprocess.call(args) == 0
11001104

11011105
def edit_config(self):
1102-
if not (os.path.isfile(self.config.config_path)):
1106+
if not os.path.isfile(self.config.config_path):
11031107
if self.interact.confirm(_("Config file does not exist - create "
11041108
"new from default? (y/N)")):
11051109
try:
11061110
default_config = pkgutil.get_data('bpython',
11071111
'sample-config')
11081112
if py3: # py3 files need unicode
11091113
default_config = default_config.decode('ascii')
1110-
bpython_dir, script_name = os.path.split(__file__)
1114+
#bpython_dir, script_name = os.path.split(__file__)
11111115
containing_dir = os.path.dirname(
11121116
os.path.abspath(self.config.config_path))
11131117
if not os.path.exists(containing_dir):
@@ -1141,10 +1145,10 @@ def next_indentation(line, tab_length):
11411145
return indentation
11421146

11431147

1144-
def next_token_inside_string(s, inside_string):
1148+
def next_token_inside_string(code_string, inside_string):
11451149
"""Given a code string s and an initial state inside_string, return
11461150
whether the next token will be inside a string or not."""
1147-
for token, value in PythonLexer().get_tokens(s):
1151+
for token, value in PythonLexer().get_tokens(code_string):
11481152
if token is Token.String:
11491153
value = value.lstrip('bBrRuU')
11501154
if value in ['"""', "'''", '"', "'"]:

0 commit comments

Comments
 (0)