-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,7 +117,7 @@ def __ior__(self, other): | |
| return self | ||
|
|
||
| def __repr__(self): | ||
| return "Vector(" + tuple.__repr__(self) + ")" | ||
| return f"Vector({tuple.__repr__(self)})" | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def norm(self): | ||
| """ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,8 +48,7 @@ def log(output): | |
| sys.stdout.flush() | ||
|
|
||
| def push(self, command): | ||
| more = self.runsource(command, self.filename) | ||
| return more | ||
| return self.runsource(command, self.filename) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def showsyntaxerror(self, filename=None): | ||
| ex_type, value, sys.last_traceback = sys.exc_info() | ||
|
|
@@ -130,10 +129,6 @@ def interact(self, banner=None): | |
| more = 0 | ||
| while True: | ||
| try: | ||
| if more: | ||
| pass # prompt = sys.ps2 | ||
| else: | ||
| pass # prompt = sys.ps1 | ||
|
Comment on lines
-133
to
-136
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ): |
||
| try: | ||
| line = self.raw_input() # prompt) | ||
| except EOFError: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,7 +63,7 @@ def __init__(self, parent=None, id=-1, title='PyShell', | |
| if size == wx.DefaultSize: | ||
| self.SetSize((750, 525)) | ||
|
|
||
| intro = 'PyShell %s - The Flakiest Python Shell' % VERSION | ||
| intro = f'PyShell {VERSION} - The Flakiest Python Shell' | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| self.SetStatusText(intro.replace('\n', ', ')) | ||
| self.shell = Shell(parent=self, id=-1, introText=intro, | ||
| locals=locals, InterpClass=InterpClass, | ||
|
|
@@ -443,7 +443,7 @@ def setLocalShell(self): | |
| def execStartupScript(self, startupScript): | ||
| """Execute the user's PYTHONSTARTUP script if they have one.""" | ||
| if startupScript and os.path.isfile(startupScript): | ||
| text = 'Startup script executed: ' + startupScript | ||
| text = f'Startup script executed: {startupScript}' | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| self.push('print %r; execfile(%r)' % (text, startupScript)) | ||
| self.interp.startupScript = startupScript | ||
| else: | ||
|
|
@@ -483,9 +483,7 @@ def OnChar(self, event): | |
| # currpos = self.GetCurrentPos() | ||
| # stoppos = self.promptPosEnd | ||
| # Return (Enter) needs to be ignored in this handler. | ||
| if key in [wx.WXK_RETURN, wx.WXK_NUMPAD_ENTER]: | ||
| pass | ||
| else: | ||
| if key not in [wx.WXK_RETURN, wx.WXK_NUMPAD_ENTER]: | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| # Allow the normal event handling to take place. | ||
| event.Skip() | ||
| """ | ||
|
|
@@ -600,11 +598,9 @@ def OnKeyDown(self, event): | |
| if not self.waiting_for_process: | ||
| self.processLine() | ||
|
|
||
| # Complete Text (from already typed words) | ||
| elif shiftDown and key in [wx.WXK_RETURN, wx.WXK_NUMPAD_ENTER]: | ||
| pass # self.OnShowCompHistory() | ||
|
|
||
| # Ctrl+Return (Ctrl+Enter) is used to insert a line break. | ||
|
Comment on lines
-603
to
-607
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ): |
||
| elif controlDown and key in [wx.WXK_RETURN, wx.WXK_NUMPAD_ENTER]: | ||
| if self.CallTipActive(): | ||
| self.CallTipCancel() | ||
|
|
@@ -613,54 +609,42 @@ def OnKeyDown(self, event): | |
| else: | ||
| self.insertLineBreak() | ||
|
|
||
| # Let Ctrl-Alt-* get handled normally. | ||
| elif controlDown and altDown: | ||
| event.Skip() | ||
|
|
||
| # Clear the current, unexecuted command. | ||
| elif key == wx.WXK_ESCAPE: | ||
| if self.CallTipActive(): | ||
| event.Skip() | ||
| else: | ||
| self.clearCommand() | ||
|
|
||
| # Clear the current command | ||
| elif key == wx.WXK_BACK and controlDown and shiftDown: | ||
| self.clearCommand() | ||
|
|
||
| # Increase font size. | ||
| elif controlDown and key in (ord(']'), wx.WXK_NUMPAD_ADD): | ||
| dispatcher.send(signal='FontIncrease') | ||
|
|
||
| # Decrease font size. | ||
| elif controlDown and key in (ord('['), wx.WXK_NUMPAD_SUBTRACT): | ||
| dispatcher.send(signal='FontDecrease') | ||
|
|
||
| # Default font size. | ||
| elif controlDown and key in (ord('='), wx.WXK_NUMPAD_DIVIDE): | ||
| dispatcher.send(signal='FontDefault') | ||
|
|
||
| # Cut to the clipboard. | ||
| elif (controlDown and key in (ord('X'), ord('x'))) \ | ||
| or (shiftDown and key == wx.WXK_DELETE): | ||
| self.Cut() | ||
|
|
||
| # Copy to the clipboard. | ||
| elif controlDown and not shiftDown \ | ||
| and key in (ord('C'), ord('c'), wx.WXK_INSERT): | ||
| self.Copy() | ||
|
|
||
| # Copy to the clipboard, including prompts. | ||
| elif controlDown and shiftDown \ | ||
| and key in (ord('C'), ord('c'), wx.WXK_INSERT): | ||
| self.CopyWithPrompts() | ||
|
|
||
| # Copy to the clipboard, including prefixed prompts. | ||
| elif altDown and not controlDown \ | ||
| and key in (ord('C'), ord('c'), wx.WXK_INSERT): | ||
| elif altDown and key in (ord('C'), ord('c'), wx.WXK_INSERT): | ||
| self.CopyWithPromptsPrefixed() | ||
|
|
||
| # Home needs to be aware of the prompt. | ||
| elif key == wx.WXK_HOME: | ||
| home = self.promptPosEnd | ||
| if currpos > home: | ||
|
|
@@ -671,50 +655,36 @@ def OnKeyDown(self, event): | |
| else: | ||
| event.Skip() | ||
|
|
||
| # | ||
| # The following handlers modify text, so we need to see if | ||
| # there is a selection that includes text prior to the prompt. | ||
| # | ||
| # Don't modify a selection with text prior to the prompt. | ||
| elif selecting and key not in NAVKEYS and not self.CanEdit(): | ||
| pass | ||
|
|
||
| # Paste from the clipboard. | ||
| elif (controlDown and not shiftDown and key in (ord('V'), ord('v'))) \ | ||
| or (shiftDown and not controlDown and key == wx.WXK_INSERT): | ||
| self.Paste() | ||
|
|
||
| # manually invoke AutoComplete and Calltips | ||
| elif controlDown and key == wx.WXK_SPACE: | ||
| pass # self.OnCallTipAutoCompleteManually(shiftDown) | ||
|
|
||
| # Paste from the clipboard, run commands. | ||
| elif controlDown and shiftDown and key in (ord('V'), ord('v')): | ||
| self.PasteAndRun() | ||
|
|
||
| # Replace with the previous command from the history buffer. | ||
| elif (controlDown and key == wx.WXK_UP) \ | ||
| or (altDown and key in (ord('P'), ord('p'))): | ||
| self.OnHistoryReplace(step=+1) | ||
|
|
||
| # Replace with the next command from the history buffer. | ||
| elif (controlDown and key == wx.WXK_DOWN) \ | ||
| or (altDown and key in (ord('N'), ord('n'))): | ||
| self.OnHistoryReplace(step=-1) | ||
|
|
||
| # Insert the previous command from the history buffer. | ||
| elif (shiftDown and key == wx.WXK_UP) and self.CanEdit(): | ||
| self.OnHistoryInsert(step=+1) | ||
|
|
||
| # Insert the next command from the history buffer. | ||
| elif (shiftDown and key == wx.WXK_DOWN) and self.CanEdit(): | ||
| self.OnHistoryInsert(step=-1) | ||
|
|
||
| # Search up the history for the text in front of the cursor. | ||
| elif key == wx.WXK_F8: | ||
| self.OnHistorySearch() | ||
|
|
||
| # Don't backspace over the latest non-continuation prompt. | ||
| elif key == wx.WXK_BACK: | ||
| if selecting and self.CanEdit(): | ||
| event.Skip() | ||
|
|
@@ -734,28 +704,22 @@ def OnKeyDown(self, event): | |
| else: | ||
| event.Skip() | ||
|
|
||
| # Only allow these keys after the latest prompt. | ||
| elif key in (wx.WXK_TAB, wx.WXK_DELETE): | ||
| if self.CanEdit(): | ||
| event.Skip() | ||
|
|
||
| # Don't toggle between insert mode and overwrite mode. | ||
| elif key == wx.WXK_INSERT: | ||
| pass | ||
|
|
||
| # Don't allow line deletion. | ||
| elif controlDown and key in (ord('L'), ord('l')): | ||
| pass | ||
|
|
||
| # Don't allow line transposition. | ||
| elif controlDown and key in (ord('T'), ord('t')): | ||
| pass | ||
|
|
||
| # Basic navigation keys should work anywhere. | ||
| elif key in NAVKEYS: | ||
| event.Skip() | ||
|
|
||
| # Protect the readonly portion of the shell. | ||
| elif not self.CanEdit(): | ||
| if key not in [wx.WXK_CONTROL, wx.WXK_ALT, wx.WXK_SHIFT]: | ||
| self.GotoPos(self.GetLength()) | ||
|
|
@@ -777,11 +741,7 @@ def OnShowCompHistory(self): | |
| newlist = re.split(r'[ \.\[\]=}(\)\,0-9"]', joined) | ||
|
|
||
| # length > 1 (mix out "trash") | ||
| thlist = [] | ||
| for i in newlist: | ||
| if len(i) > 1: | ||
| thlist.append(i) | ||
|
|
||
| thlist = [i for i in newlist if len(i) > 1] | ||
|
Comment on lines
-780
to
+744
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| # unique (no duplicate words | ||
| # oneliner from german python forum => unique list | ||
| unlist = [thlist[i] for i in range(len(thlist)) | ||
|
|
@@ -916,19 +876,15 @@ def processLine(self): | |
| else: | ||
| self.push(command) | ||
| wx.CallLater(1, self.EnsureCaretVisible) | ||
| # Or replace the current command with the other command. | ||
| elif self.getCommand(rstrip=False): | ||
| command = self.getMultilineCommand() | ||
| self.clearCommand() | ||
| self.write(command) | ||
| else: | ||
| # If the line contains a command (even an invalid one). | ||
| if self.getCommand(rstrip=False): | ||
| command = self.getMultilineCommand() | ||
| self.clearCommand() | ||
| self.write(command) | ||
| # Otherwise, put the cursor back where we started. | ||
| else: | ||
| self.SetCurrentPos(thepos) | ||
| self.SetAnchor(thepos) | ||
| self.SetCurrentPos(thepos) | ||
| self.SetAnchor(thepos) | ||
|
|
||
| self.GotoPos(self.GetLength()) | ||
| self.GotoPos(self.GetLength()) | ||
|
Comment on lines
-919
to
+887
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ): |
||
|
|
||
| def getMultilineCommand(self, rstrip=True): | ||
| """Extract a multi-line command from the editor. | ||
|
|
@@ -1007,9 +963,8 @@ def push(self, command, silent=False): | |
| self.addHistory(command.rstrip()) | ||
| if self.process_shell: | ||
| self.waiting_for_process = True | ||
| else: | ||
| if not silent: | ||
| self.prompt() | ||
| elif not silent: | ||
| self.prompt() | ||
|
Comment on lines
-1010
to
+967
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def addHistory(self, command): | ||
| """Add command to the command history.""" | ||
|
|
@@ -1113,8 +1068,7 @@ def ask(self, prompt='Please enter your response:'): | |
| 'Input Dialog (Raw)', '') | ||
| try: | ||
| if dialog.ShowModal() == wx.ID_OK: | ||
| text = dialog.GetValue() | ||
| return text | ||
| return dialog.GetValue() | ||
|
Comment on lines
-1116
to
+1071
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| finally: | ||
| dialog.Destroy() | ||
| return '' | ||
|
|
@@ -1163,12 +1117,12 @@ def autoCompleteShow(self, command, offset=0): | |
| """Display auto-completion popup list.""" | ||
| self.AutoCompSetAutoHide(self.autoCompleteAutoHide) | ||
| self.AutoCompSetIgnoreCase(self.autoCompleteCaseInsensitive) | ||
| autocomp_list = self.interp.getAutoCompleteList( | ||
| if autocomp_list := self.interp.getAutoCompleteList( | ||
| command, | ||
| includeMagic=self.autoCompleteIncludeMagic, | ||
| includeSingle=self.autoCompleteIncludeSingle, | ||
| includeDouble=self.autoCompleteIncludeDouble) | ||
| if autocomp_list: | ||
| includeDouble=self.autoCompleteIncludeDouble, | ||
| ): | ||
|
Comment on lines
-1166
to
+1125
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| options = ' '.join(autocomp_list) | ||
| # offset = 0 | ||
| self.AutoCompShow(offset, options) | ||
|
|
@@ -1184,7 +1138,7 @@ def autoCallTipShow(self, command, insertcalltip=True, forceCallTip=False): | |
| return | ||
| if argspec and insertcalltip and self.callTipInsert: | ||
| startpos = self.GetCurrentPos() | ||
| self.write(argspec + ')') | ||
| self.write(f'{argspec})') | ||
|
Comment on lines
-1187
to
+1141
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| endpos = self.GetCurrentPos() | ||
| self.SetSelection(endpos, startpos) | ||
| if tip: | ||
|
|
@@ -1255,49 +1209,36 @@ def writeErr(self, text): | |
|
|
||
| def redirectStdin(self, redirect=True): | ||
| """If redirect is true then sys.stdin will come from the shell.""" | ||
| if redirect: | ||
| sys.stdin = self.reader | ||
| else: | ||
| sys.stdin = self.stdin | ||
| sys.stdin = self.reader if redirect else self.stdin | ||
|
Comment on lines
-1258
to
+1212
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def redirectStdout(self, redirect=True): | ||
| """If redirect is true then sys.stdout will go to the shell.""" | ||
| if redirect: | ||
| sys.stdout = PseudoFileOut(self.writeOut) | ||
| else: | ||
| sys.stdout = self.stdout | ||
| sys.stdout = PseudoFileOut(self.writeOut) if redirect else self.stdout | ||
|
Comment on lines
-1265
to
+1216
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def redirectStderr(self, redirect=True): | ||
| """If redirect is true then sys.stderr will go to the shell.""" | ||
| if redirect: | ||
| sys.stderr = PseudoFileErr(self.writeErr) | ||
| else: | ||
| sys.stderr = self.stderr | ||
| sys.stderr = PseudoFileErr(self.writeErr) if redirect else self.stderr | ||
|
Comment on lines
-1272
to
+1220
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def CanCut(self): | ||
| """Return true if text is selected and can be cut.""" | ||
| if self.GetSelectionStart() != self.GetSelectionEnd() \ | ||
| and self.GetSelectionStart() >= self.promptPosEnd \ | ||
| and self.GetSelectionEnd() >= self.promptPosEnd: | ||
| return True | ||
| else: | ||
| return False | ||
| return ( | ||
| self.GetSelectionStart() != self.GetSelectionEnd() | ||
| and self.GetSelectionStart() >= self.promptPosEnd | ||
| and self.GetSelectionEnd() >= self.promptPosEnd | ||
| ) | ||
|
Comment on lines
-1279
to
+1228
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def CanPaste(self): | ||
| """Return true if a paste should succeed.""" | ||
| if self.CanEdit() and editwindow.EditWindow.CanPaste(self): | ||
| return True | ||
| else: | ||
| return False | ||
| return bool(self.CanEdit() and editwindow.EditWindow.CanPaste(self)) | ||
|
Comment on lines
-1288
to
+1232
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def CanEdit(self): | ||
| """Return true if editing should succeed.""" | ||
| if self.GetSelectionStart() != self.GetSelectionEnd(): | ||
| if self.GetSelectionStart() >= self.promptPosEnd \ | ||
| and self.GetSelectionEnd() >= self.promptPosEnd: | ||
| return True | ||
| else: | ||
| return False | ||
| return ( | ||
| self.GetSelectionStart() >= self.promptPosEnd | ||
| and self.GetSelectionEnd() >= self.promptPosEnd | ||
| ) | ||
|
|
||
| else: | ||
| return self.GetCurrentPos() >= self.promptPosEnd | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,11 +92,11 @@ def rmtree_glob(file_glob): | |
| for item in glob(file_glob, recursive=True): | ||
| try: | ||
| os.remove(item) | ||
| print('%s removed ...' % item) | ||
| print(f'{item} removed ...') | ||
| except OSError: | ||
| try: | ||
| shutil.rmtree(item) | ||
| print('%s/ removed ...' % item) | ||
| print(f'{item}/ removed ...') | ||
|
Comment on lines
-95
to
+99
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| except OSError as err: | ||
| print(err) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
page_listrefactored with the following changes:inline-immediately-returned-variable)