mirror of
				https://github.com/python/cpython.git
				synced 2025-11-01 06:01:29 +00:00 
			
		
		
		
	gh-102541: Fix Helper.help("mod") for non-existent mod (#105934)
If the output arg to Helper() is a stream rather than the default None, which means 'page to stdout', the ImportError from pydoc.resolve is currently not caught in pydoc.doc. The same error is caught when output is None. --------- Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
This commit is contained in:
		
							parent
							
								
									46d77610fc
								
							
						
					
					
						commit
						0530f4f646
					
				
					 3 changed files with 13 additions and 1 deletions
				
			
		|  | @ -1790,7 +1790,11 @@ def doc(thing, title='Python Library Documentation: %s', forceload=0, | ||||||
|                 raise |                 raise | ||||||
|             print(exc) |             print(exc) | ||||||
|     else: |     else: | ||||||
|         output.write(render_doc(thing, title, forceload, plaintext)) |         try: | ||||||
|  |             s = render_doc(thing, title, forceload, plaintext) | ||||||
|  |         except ImportError as exc: | ||||||
|  |             s = str(exc) | ||||||
|  |         output.write(s) | ||||||
| 
 | 
 | ||||||
| def writedoc(thing, forceload=0): | def writedoc(thing, forceload=0): | ||||||
|     """Write HTML documentation to a file in the current directory.""" |     """Write HTML documentation to a file in the current directory.""" | ||||||
|  |  | ||||||
|  | @ -631,6 +631,13 @@ def test_builtin_on_metaclasses(self): | ||||||
|         # Testing that the subclasses section does not appear |         # Testing that the subclasses section does not appear | ||||||
|         self.assertNotIn('Built-in subclasses', text) |         self.assertNotIn('Built-in subclasses', text) | ||||||
| 
 | 
 | ||||||
|  |     def test_fail_help_output_redirect(self): | ||||||
|  |         with StringIO() as buf: | ||||||
|  |             helper = pydoc.Helper(output=buf) | ||||||
|  |             helper.help("abd") | ||||||
|  |             expected = missing_pattern % "abd" | ||||||
|  |             self.assertEqual(expected, buf.getvalue().strip().replace('\n', os.linesep)) | ||||||
|  | 
 | ||||||
|     @unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(), |     @unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(), | ||||||
|                      'trace function introduces __locals__ unexpectedly') |                      'trace function introduces __locals__ unexpectedly') | ||||||
|     @requires_docstrings |     @requires_docstrings | ||||||
|  |  | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | Make pydoc.doc catch bad module ImportError when output stream is not None. | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Kirill Podoprigora
						Kirill Podoprigora