| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 819df4e commit efdec6c
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -146,8 +146,10 @@ | |||
| 146 | 146 | ||
| 147 | 147 | ||
| 148 | 148 | if sys.version_info < (3, 13): | |
| 149 | + | ||
| 149 | 150 | class OldPdb(PdbClosureBackport, _OldPdb): | |
| 150 | 151 | pass | |
| 152 | + | ||
| 151 | 153 | else: | |
| 152 | 154 | OldPdb = _OldPdb | |
| 153 | 155 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,6 +55,7 @@ | |||
| 55 | 55 | agrees to be bound by the terms and conditions of this License | |
| 56 | 56 | Agreement. | |
| 57 | 57 | """ | |
| 58 | + | ||
| 58 | 59 | import sys | |
| 59 | 60 | import types | |
| 60 | 61 | import codeop | |
@@ -64,9 +65,9 @@ | |||
| 64 | 65 | ||
| 65 | 66 | class PdbClosureBackport: | |
| 66 | 67 | def _exec_in_closure(self, source, globals, locals): | |
| 67 | - """ Run source code in closure so code object created within source | ||
| 68 | - can find variables in locals correctly | ||
| 69 | - returns True if the source is executed, False otherwise | ||
| 68 | + """Run source code in closure so code object created within source | ||
| 69 | + can find variables in locals correctly | ||
| 70 | + returns True if the source is executed, False otherwise | ||
| 70 | 71 | """ | |
| 71 | 72 | ||
| 72 | 73 | # Determine if the source should be executed in closure. Only when the | |
@@ -81,10 +82,7 @@ def _exec_in_closure(self, source, globals, locals): | |||
| 81 | 82 | # copy it first to avoid modifying the original locals | |
| 82 | 83 | locals_copy = dict(locals) | |
| 83 | 84 | ||
| 84 | - locals_copy["__pdb_eval__"] = { | ||
| 85 | - "result": None, | ||
| 86 | - "write_back": {} | ||
| 87 | - } | ||
| 85 | + locals_copy["__pdb_eval__"] = {"result": None, "write_back": {}} | ||
| 88 | 86 | ||
| 89 | 87 | # If the source is an expression, we need to print its value | |
| 90 | 88 | try: | |
@@ -95,10 +93,13 @@ def _exec_in_closure(self, source, globals, locals): | |||
| 95 | 93 | source = "__pdb_eval__['result'] = " + source | |
| 96 | 94 | ||
| 97 | 95 | # Add write-back to update the locals | |
| 98 | - source = ("try:\n" + | ||
| 99 | - textwrap.indent(source, " ") + "\n" + | ||
| 100 | - "finally:\n" + | ||
| 101 | - " __pdb_eval__['write_back'] = locals()") | ||
| 96 | + source = ( | ||
| 97 | + "try:\n" | ||
| 98 | + + textwrap.indent(source, " ") | ||
| 99 | + + "\n" | ||
| 100 | + + "finally:\n" | ||
| 101 | + + " __pdb_eval__['write_back'] = locals()" | ||
| 102 | + ) | ||
| 102 | 103 | ||
| 103 | 104 | # Build a closure source code with freevars from locals like: | |
| 104 | 105 | # def __pdb_outer(): | |
@@ -107,13 +108,17 @@ def _exec_in_closure(self, source, globals, locals): | |||
| 107 | 108 | # nonlocal var | |
| 108 | 109 | # <source> | |
| 109 | 110 | # return __pdb_scope.__code__ | |
| 110 | - source_with_closure = ("def __pdb_outer():\n" + | ||
| 111 | - "\n".join(f" {var} = None" for var in locals_copy) + "\n" + | ||
| 112 | - " def __pdb_scope():\n" + | ||
| 113 | - "\n".join(f" nonlocal {var}" for var in locals_copy) + "\n" + | ||
| 114 | - textwrap.indent(source, " ") + "\n" + | ||
| 115 | - " return __pdb_scope.__code__" | ||
| 116 | - ) | ||
| 111 | + source_with_closure = ( | ||
| 112 | + "def __pdb_outer():\n" | ||
| 113 | + + "\n".join(f" {var} = None" for var in locals_copy) | ||
| 114 | + + "\n" | ||
| 115 | + + " def __pdb_scope():\n" | ||
| 116 | + + "\n".join(f" nonlocal {var}" for var in locals_copy) | ||
| 117 | + + "\n" | ||
| 118 | + + textwrap.indent(source, " ") | ||
| 119 | + + "\n" | ||
| 120 | + + " return __pdb_scope.__code__" | ||
| 121 | + ) | ||
| 117 | 122 | ||
| 118 | 123 | # Get the code object of __pdb_scope() | |
| 119 | 124 | # The exec fills locals_copy with the __pdb_outer() function and we can call | |
@@ -147,36 +152,41 @@ def _exec_in_closure(self, source, globals, locals): | |||
| 147 | 152 | return True | |
| 148 | 153 | ||
| 149 | 154 | def default(self, line): | |
| 150 | - if line[:1] == '!': line = line[1:].strip() | ||
| 155 | + if line[:1] == "!": | ||
| 156 | + line = line[1:].strip() | ||
| 151 | 157 | locals = self.curframe_locals | |
| 152 | 158 | globals = self.curframe.f_globals | |
| 153 | 159 | try: | |
| 154 | 160 | buffer = line | |
| 155 | - if (code := codeop.compile_command(line + '\n', '<stdin>', 'single')) is None: | ||
| 161 | + if ( | ||
| 162 | + code := codeop.compile_command(line + "\n", "<stdin>", "single") | ||
| 163 | + ) is None: | ||
| 156 | 164 | # Multi-line mode | |
| 157 | 165 | with self._disable_command_completion(): | |
| 158 | 166 | buffer = line | |
| 159 | 167 | continue_prompt = "... " | |
| 160 | - while (code := codeop.compile_command(buffer, '<stdin>', 'single')) is None: | ||
| 168 | + while ( | ||
| 169 | + code := codeop.compile_command(buffer, "<stdin>", "single") | ||
| 170 | + ) is None: | ||
| 161 | 171 | if self.use_rawinput: | |
| 162 | 172 | try: | |
| 163 | 173 | line = input(continue_prompt) | |
| 164 | 174 | except (EOFError, KeyboardInterrupt): | |
| 165 | 175 | self.lastcmd = "" | |
| 166 | - print('\n') | ||
| 176 | + print("\n") | ||
| 167 | 177 | return | |
| 168 | 178 | else: | |
| 169 | 179 | self.stdout.write(continue_prompt) | |
| 170 | 180 | self.stdout.flush() | |
| 171 | 181 | line = self.stdin.readline() | |
| 172 | 182 | if not len(line): | |
| 173 | 183 | self.lastcmd = "" | |
| 174 | - self.stdout.write('\n') | ||
| 184 | + self.stdout.write("\n") | ||
| 175 | 185 | self.stdout.flush() | |
| 176 | 186 | return | |
| 177 | 187 | else: | |
| 178 | - line = line.rstrip('\r\n') | ||
| 179 | - buffer += '\n' + line | ||
| 188 | + line = line.rstrip("\r\n") | ||
| 189 | + buffer += "\n" + line | ||
| 180 | 190 | save_stdout = sys.stdout | |
| 181 | 191 | save_stdin = sys.stdin | |
| 182 | 192 | save_displayhook = sys.displayhook | |
@@ -191,4 +201,4 @@ def default(self, line): | |||
| 191 | 201 | sys.stdin = save_stdin | |
| 192 | 202 | sys.displayhook = save_displayhook | |
| 193 | 203 | except: | |
| 194 | - self._error_exc() | ||
| 204 | + self._error_exc() | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments