Skip to content

Commit 5b406c1

Browse files
committed
PEP-8
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
1 parent 997dfb6 commit 5b406c1

27 files changed

+432
-249
lines changed

bpython/args.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ def error(self, msg):
2424

2525
def version_banner():
2626
return 'bpython version %s on top of Python %s %s' % (
27-
__version__, sys.version.split()[0], sys.executable)
27+
__version__, sys.version.split()[0], sys.executable)
28+
2829

2930
def parse(args, extras=None, ignore_stdin=False):
3031
"""Receive an argument list - if None, use sys.argv - parse all args and
@@ -37,11 +38,12 @@ def parse(args, extras=None, ignore_stdin=False):
3738
3839
e.g.:
3940
40-
parse(['-i', '-m', 'foo.py'],
41-
('Front end-specific options',
42-
'A full description of what these options are for',
43-
[optparse.Option('-f', action='store_true', dest='f', help='Explode'),
44-
optparse.Option('-l', action='store_true', dest='l', help='Love')]))
41+
parse(
42+
['-i', '-m', 'foo.py'],
43+
('Front end-specific options',
44+
'A full description of what these options are for',
45+
[optparse.Option('-f', action='store_true', dest='f', help='Explode'),
46+
optparse.Option('-l', action='store_true', dest='l', help='Love')]))
4547
4648
4749
Return a tuple of (config, options, exec_args) wherein "config" is the
@@ -55,9 +57,9 @@ def parse(args, extras=None, ignore_stdin=False):
5557

5658
parser = RaisingOptionParser(
5759
usage=_('Usage: %prog [options] [file [args]]\n'
58-
'NOTE: If bpython sees an argument it does '
59-
'not know, execution falls back to the '
60-
'regular Python interpreter.'))
60+
'NOTE: If bpython sees an argument it does '
61+
'not know, execution falls back to the '
62+
'regular Python interpreter.'))
6163
# This is not sufficient if bpython gains its own -m support
6264
# (instead of falling back to Python itself for that).
6365
# That's probably fixable though, for example by having that
@@ -67,7 +69,7 @@ def parse(args, extras=None, ignore_stdin=False):
6769
help=_('Use CONFIG instead of default config file.'))
6870
parser.add_option('--interactive', '-i', action='store_true',
6971
help=_('Drop to bpython shell after running file '
70-
'instead of exiting.'))
72+
'instead of exiting.'))
7173
parser.add_option('--quiet', '-q', action='store_true',
7274
help=_("Don't flush the output to stdout."))
7375
parser.add_option('--version', '-V', action='store_true',
@@ -102,6 +104,7 @@ def parse(args, extras=None, ignore_stdin=False):
102104

103105
return config, options, args
104106

107+
105108
def exec_code(interpreter, args):
106109
"""
107110
Helper to execute code in a given interpreter. args should be a [faked]

bpython/autocomplete.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ def matches(self, cursor_offset, line, **kwargs):
288288
matches.add(word)
289289
for nspace in [builtins.__dict__, locals_]:
290290
for word, val in nspace.items():
291-
if method_match(word, len(text), text) and word != "__builtins__":
291+
if (method_match(word, len(text), text) and
292+
word != "__builtins__"):
292293
matches.add(_callable_postfix(val, word))
293294
return matches
294295

@@ -373,7 +374,8 @@ def matches(self, cursor_offset, line, **kwargs):
373374
first_letter = line[self._orig_start:self._orig_start+1]
374375

375376
matches = [c.name for c in completions]
376-
if any(not m.lower().startswith(matches[0][0].lower()) for m in matches):
377+
if any(not m.lower().startswith(matches[0][0].lower())
378+
for m in matches):
377379
# Too general - giving completions starting with multiple
378380
# letters
379381
return None
@@ -386,7 +388,6 @@ def locate(self, cursor_offset, line):
386388
end = cursor_offset
387389
return start, end, line[start:end]
388390

389-
390391
class MultilineJediCompletion(JediCompletion):
391392
def matches(self, cursor_offset, line, **kwargs):
392393
if 'current_block' not in kwargs or 'history' not in kwargs:

bpython/clipboard.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ def get_clipboard():
6565
if platform.system() == 'Darwin':
6666
if command_exists('pbcopy'):
6767
return OSXClipboard()
68-
if platform.system() in ('Linux', 'FreeBSD', 'OpenBSD') and os.getenv('DISPLAY') is not None:
68+
if (platform.system() in ('Linux', 'FreeBSD', 'OpenBSD') and
69+
os.getenv('DISPLAY') is not None):
6970
if command_exists('xclip'):
7071
return XClipboard()
7172

bpython/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ def get_key_no_doublebind(command):
148148
try:
149149
default_command = default_keys_to_commands[requested_key]
150150

151-
if default_commands_to_keys[default_command] == \
152-
config.get('keyboard', default_command):
151+
if (default_commands_to_keys[default_command] ==
152+
config.get('keyboard', default_command)):
153153
setattr(struct, '%s_key' % default_command, '')
154154
except KeyError:
155155
pass

bpython/curtsies.py

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def main(args=None, locals_=None, banner=None):
3333
Option('--log', '-L', action='count',
3434
help=_("log debug messages to bpython.log")),
3535
Option('--type', '-t', action='store_true',
36-
help=_("enter lines of file as though interactively typed")),
36+
help=_("enter lines of file as though interactively "
37+
"typed")),
3738
]))
3839
if options.log is None:
3940
options.log = 0
@@ -67,25 +68,35 @@ def main(args=None, locals_=None, banner=None):
6768
if not options.interactive:
6869
raise SystemExit(exit_value)
6970
else:
70-
sys.path.insert(0, '') # expected for interactive sessions (vanilla python does it)
71+
# expected for interactive sessions (vanilla python does it)
72+
sys.path.insert(0, '')
7173

7274
print(bpargs.version_banner())
73-
mainloop(config, locals_, banner, interp, paste, interactive=(not exec_args))
75+
mainloop(config, locals_, banner, interp, paste,
76+
interactive=(not exec_args))
7477

75-
def mainloop(config, locals_, banner, interp=None, paste=None, interactive=True):
76-
with curtsies.input.Input(keynames='curtsies', sigint_event=True) as input_generator:
78+
79+
def mainloop(config, locals_, banner, interp=None, paste=None,
80+
interactive=True):
81+
with curtsies.input.Input(keynames='curtsies', sigint_event=True) as \
82+
input_generator:
7783
with curtsies.window.CursorAwareWindow(
7884
sys.stdout,
7985
sys.stdin,
8086
keep_last_line=True,
8187
hide_cursor=False,
8288
extra_bytes_callback=input_generator.unget_bytes) as window:
8389

84-
request_refresh = input_generator.event_trigger(bpythonevents.RefreshRequestEvent)
85-
schedule_refresh = input_generator.scheduled_event_trigger(bpythonevents.ScheduledRefreshRequestEvent)
86-
request_reload = input_generator.threadsafe_event_trigger(bpythonevents.ReloadEvent)
87-
interrupting_refresh = input_generator.threadsafe_event_trigger(lambda: None)
88-
request_undo = input_generator.event_trigger(bpythonevents.UndoEvent)
90+
request_refresh = input_generator.event_trigger(
91+
bpythonevents.RefreshRequestEvent)
92+
schedule_refresh = input_generator.scheduled_event_trigger(
93+
bpythonevents.ScheduledRefreshRequestEvent)
94+
request_reload = input_generator.threadsafe_event_trigger(
95+
bpythonevents.ReloadEvent)
96+
interrupting_refresh = input_generator.threadsafe_event_trigger(
97+
lambda: None)
98+
request_undo = input_generator.event_trigger(
99+
bpythonevents.UndoEvent)
89100

90101
def on_suspend():
91102
window.__exit__(None, None, None)
@@ -96,7 +107,8 @@ def after_suspend():
96107
window.__enter__()
97108
interrupting_refresh()
98109

99-
global repl # global for easy introspection `from bpython.curtsies import repl`
110+
# global for easy introspection `from bpython.curtsies import repl`
111+
global repl
100112
with Repl(config=config,
101113
locals_=locals_,
102114
request_refresh=request_refresh,
@@ -119,7 +131,10 @@ def process_event(e):
119131
if e is not None:
120132
repl.process_event(e)
121133
except (SystemExitFromCodeGreenlet, SystemExit) as err:
122-
array, cursor_pos = repl.paint(about_to_exit=True, user_quit=isinstance(err, SystemExitFromCodeGreenlet))
134+
array, cursor_pos = repl.paint(
135+
about_to_exit=True,
136+
user_quit=isinstance(err,
137+
SystemExitFromCodeGreenlet))
123138
scrolled = window.render_to_terminal(array, cursor_pos)
124139
repl.scroll_offset += scrolled
125140
raise
@@ -134,7 +149,8 @@ def process_event(e):
134149
repl.coderunner.interp.locals['_repl'] = repl
135150

136151
repl.coderunner.interp.runsource(
137-
'from bpython.curtsiesfrontend._internal import _Helper')
152+
'from bpython.curtsiesfrontend._internal '
153+
'import _Helper')
138154
repl.coderunner.interp.runsource('help = _Helper(_repl)\n')
139155

140156
del repl.coderunner.interp.locals['_repl']
@@ -147,7 +163,8 @@ def process_event(e):
147163
if paste:
148164
process_event(paste)
149165

150-
process_event(None) # do a display before waiting for first event
166+
# do a display before waiting for first event
167+
process_event(None)
151168
for unused in find_iterator:
152169
e = input_generator.send(0)
153170
if e is not None:
@@ -156,5 +173,6 @@ def process_event(e):
156173
for e in input_generator:
157174
process_event(e)
158175

176+
159177
if __name__ == '__main__':
160178
sys.exit(main())

bpython/formatter.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626

2727
from pygments.formatter import Formatter
2828
from pygments.token import Keyword, Name, Comment, String, Error, \
29-
Number, Operator, Token, Whitespace, Literal, \
30-
Punctuation
29+
Number, Operator, Token, Whitespace, Literal, Punctuation
3130
from six import iteritems
3231

3332
"""These format strings are pretty ugly.

bpython/inspection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def parsekeywordpairs(signature):
134134
# End of signature reached
135135
break
136136
if ((value == ',' and parendepth == 0) or
137-
(value == ')' and parendepth == -1)):
137+
(value == ')' and parendepth == -1)):
138138
stack.append(substack)
139139
substack = []
140140
continue
@@ -231,8 +231,8 @@ def getargspec(func, f):
231231

232232
try:
233233
is_bound_method = ((inspect.ismethod(f) and f.im_self is not None)
234-
or (func_name == '__init__' and not
235-
func.endswith('.__init__')))
234+
or (func_name == '__init__' and not
235+
func.endswith('.__init__')))
236236
except:
237237
# if f is a method from a xmlrpclib.Server instance, func_name ==
238238
# '__init__' throws xmlrpclib.Fault (see #202)

bpython/line.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,16 @@ def current_dict(cursor_offset, line):
5353

5454

5555
current_string_re = LazyReCompile(
56-
'''(?P<open>(?:""")|"|(?:''\')|')(?:((?P<closed>.+?)(?P=open))|(?P<unclosed>.+))''')
56+
'''(?P<open>(?:""")|"|(?:''\')|')(?:((?P<closed>.+?)(?P=open))|'''
57+
'''(?P<unclosed>.+))''')
5758

5859

5960
def current_string(cursor_offset, line):
60-
"""If inside a string of nonzero length, return the string (excluding quotes)
61+
"""If inside a string of nonzero length, return the string (excluding
62+
quotes)
6163
62-
Weaker than bpython.Repl's current_string, because that checks that a string is a string
63-
based on previous lines in the buffer"""
64+
Weaker than bpython.Repl's current_string, because that checks that a
65+
string is a string based on previous lines in the buffer."""
6466
for m in current_string_re.finditer(line):
6567
i = 3 if m.group(3) else 4
6668
if m.start(i) <= cursor_offset and m.end(i) >= cursor_offset:
@@ -72,9 +74,11 @@ def current_string(cursor_offset, line):
7274

7375

7476
def current_object(cursor_offset, line):
75-
"""If in attribute completion, the object on which attribute should be looked up"""
77+
"""If in attribute completion, the object on which attribute should be
78+
looked up."""
7679
match = current_word(cursor_offset, line)
77-
if match is None: return None
80+
if match is None:
81+
return None
7882
start, end, word = match
7983
matches = current_object_re.finditer(word)
8084
s = ''
@@ -94,33 +98,36 @@ def current_object(cursor_offset, line):
9498
def current_object_attribute(cursor_offset, line):
9599
"""If in attribute completion, the attribute being completed"""
96100
match = current_word(cursor_offset, line)
97-
if match is None: return None
101+
if match is None:
102+
return None
98103
start, end, word = match
99104
matches = current_object_attribute_re.finditer(word)
100105
next(matches)
101106
for m in matches:
102-
if m.start(1) + start <= cursor_offset and m.end(1) + start >= cursor_offset:
107+
if (m.start(1) + start <= cursor_offset and
108+
m.end(1) + start >= cursor_offset):
103109
return m.start(1) + start, m.end(1) + start, m.group(1)
104110
return None
105111

106112

107-
current_from_import_from_re = LazyReCompile(r'from ([\w0-9_.]*)(?:\s+import\s+([\w0-9_]+[,]?\s*)+)*')
113+
current_from_import_from_re = LazyReCompile(
114+
r'from ([\w0-9_.]*)(?:\s+import\s+([\w0-9_]+[,]?\s*)+)*')
108115

109116

110117
def current_from_import_from(cursor_offset, line):
111118
"""If in from import completion, the word after from
112119
113-
returns None if cursor not in or just after one of the two interesting parts
114-
of an import: from (module) import (name1, name2)
120+
returns None if cursor not in or just after one of the two interesting
121+
parts of an import: from (module) import (name1, name2)
115122
"""
116-
#TODO allow for as's
123+
# TODO allow for as's
117124
tokens = line.split()
118125
if not ('from' in tokens or 'import' in tokens):
119126
return None
120127
matches = current_from_import_from_re.finditer(line)
121128
for m in matches:
122129
if ((m.start(1) < cursor_offset and m.end(1) >= cursor_offset) or
123-
(m.start(2) < cursor_offset and m.end(2) >= cursor_offset)):
130+
(m.start(2) < cursor_offset and m.end(2) >= cursor_offset)):
124131
return m.start(1), m.end(1), m.group(1)
125132
return None
126133

@@ -156,7 +163,7 @@ def current_from_import_import(cursor_offset, line):
156163

157164

158165
def current_import(cursor_offset, line):
159-
#TODO allow for multiple as's
166+
# TODO allow for multiple as's
160167
baseline = current_import_re_1.search(line)
161168
if baseline is None:
162169
return None
@@ -207,7 +214,8 @@ def current_dotted_attribute(cursor_offset, line):
207214

208215
current_string_literal_attr_re = LazyReCompile(
209216
"('''" +
210-
r'''|"""|'|")((?:(?=([^"'\\]+|\\.|(?!\1)["']))\3)*)\1[.]([a-zA-Z_]?[\w]*)''')
217+
r'''|"""|'|")''' +
218+
r'''((?:(?=([^"'\\]+|\\.|(?!\1)["']))\3)*)\1[.]([a-zA-Z_]?[\w]*)''')
211219

212220

213221
def current_string_literal_attr(cursor_offset, line):

0 commit comments

Comments
 (0)