mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	bpo-40807: Show warnings once from codeop._maybe_compile (GH-20486)
* bpo-40807: Show warnings once from codeop._maybe_compile
* Move catch_warnings
* news
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
(cherry picked from commit 052d3fc090)
Co-authored-by: Cheryl Sabella <cheryl.sabella@gmail.com>
			
			
This commit is contained in:
		
							parent
							
								
									e4e5ec18e2
								
							
						
					
					
						commit
						3dfe549bfa
					
				
					 3 changed files with 19 additions and 8 deletions
				
			
		|  | @ -57,6 +57,7 @@ | |||
| """ | ||||
| 
 | ||||
| import __future__ | ||||
| import warnings | ||||
| 
 | ||||
| _features = [getattr(__future__, fname) | ||||
|              for fname in __future__.all_feature_names] | ||||
|  | @ -83,15 +84,18 @@ def _maybe_compile(compiler, source, filename, symbol): | |||
|     except SyntaxError: | ||||
|         pass | ||||
| 
 | ||||
|     try: | ||||
|         code1 = compiler(source + "\n", filename, symbol) | ||||
|     except SyntaxError as e: | ||||
|         err1 = e | ||||
|     # Suppress warnings after the first compile to avoid duplication. | ||||
|     with warnings.catch_warnings(): | ||||
|         warnings.simplefilter("ignore") | ||||
|         try: | ||||
|             code1 = compiler(source + "\n", filename, symbol) | ||||
|         except SyntaxError as e: | ||||
|             err1 = e | ||||
| 
 | ||||
|     try: | ||||
|         code2 = compiler(source + "\n\n", filename, symbol) | ||||
|     except SyntaxError as e: | ||||
|         err2 = e | ||||
|         try: | ||||
|             code2 = compiler(source + "\n\n", filename, symbol) | ||||
|         except SyntaxError as e: | ||||
|             err2 = e | ||||
| 
 | ||||
|     try: | ||||
|         if code: | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Miss Islington (bot)
						Miss Islington (bot)