mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Turn SyntasWarning into SyntaxError for all code entered
interactively.
This commit is contained in:
		
							parent
							
								
									55a0034682
								
							
						
					
					
						commit
						b4ce43011e
					
				
					 1 changed files with 12 additions and 1 deletions
				
			
		|  | @ -5,6 +5,7 @@ | ||||||
| import string | import string | ||||||
| import getopt | import getopt | ||||||
| import re | import re | ||||||
|  | import warnings | ||||||
| 
 | 
 | ||||||
| import linecache | import linecache | ||||||
| from code import InteractiveInterpreter | from code import InteractiveInterpreter | ||||||
|  | @ -180,7 +181,14 @@ def runsource(self, source): | ||||||
|         # Extend base class to stuff the source in the line cache first |         # Extend base class to stuff the source in the line cache first | ||||||
|         filename = self.stuffsource(source) |         filename = self.stuffsource(source) | ||||||
|         self.more = 0 |         self.more = 0 | ||||||
|         return InteractiveInterpreter.runsource(self, source, filename) |         self.save_warnings_filters = warnings.filters[:] | ||||||
|  |         warnings.filterwarnings(action="error", category=SyntaxWarning) | ||||||
|  |         try: | ||||||
|  |             return InteractiveInterpreter.runsource(self, source, filename) | ||||||
|  |         finally: | ||||||
|  |             if self.save_warnings_filters is not None: | ||||||
|  |                 warnings.filters[:] = self.save_warnings_filters | ||||||
|  |                 self.save_warnings_filters = None | ||||||
| 
 | 
 | ||||||
|     def stuffsource(self, source): |     def stuffsource(self, source): | ||||||
|         # Stuff source in the filename cache |         # Stuff source in the filename cache | ||||||
|  | @ -249,6 +257,9 @@ def getdebugger(self): | ||||||
| 
 | 
 | ||||||
|     def runcode(self, code): |     def runcode(self, code): | ||||||
|         # Override base class method |         # Override base class method | ||||||
|  |         if self.save_warnings_filters is not None: | ||||||
|  |             warnings.filters[:] = self.save_warnings_filters | ||||||
|  |             self.save_warnings_filters = None | ||||||
|         debugger = self.debugger |         debugger = self.debugger | ||||||
|         try: |         try: | ||||||
|             self.tkconsole.beginexecuting() |             self.tkconsole.beginexecuting() | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Guido van Rossum
						Guido van Rossum