mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	bpo-33689: Blank lines in .pth file cause a duplicate sys.path entry (GH-20679)
This commit is contained in:
		
							parent
							
								
									ae0d2a33ec
								
							
						
					
					
						commit
						0c71a66b53
					
				
					 3 changed files with 12 additions and 1 deletions
				
			
		|  | @ -170,6 +170,8 @@ def addpackage(sitedir, name, known_paths): | ||||||
|         for n, line in enumerate(f): |         for n, line in enumerate(f): | ||||||
|             if line.startswith("#"): |             if line.startswith("#"): | ||||||
|                 continue |                 continue | ||||||
|  |             if line.strip() == "": | ||||||
|  |                 continue | ||||||
|             try: |             try: | ||||||
|                 if line.startswith(("import ", "import\t")): |                 if line.startswith(("import ", "import\t")): | ||||||
|                     exec(line) |                     exec(line) | ||||||
|  |  | ||||||
|  | @ -161,6 +161,12 @@ def test_addpackage_import_bad_exec(self): | ||||||
|         self.assertRegex(err_out.getvalue(), 'Traceback') |         self.assertRegex(err_out.getvalue(), 'Traceback') | ||||||
|         self.assertRegex(err_out.getvalue(), 'ModuleNotFoundError') |         self.assertRegex(err_out.getvalue(), 'ModuleNotFoundError') | ||||||
| 
 | 
 | ||||||
|  |     def test_addpackage_empty_lines(self): | ||||||
|  |         # Issue 33689 | ||||||
|  |         pth_dir, pth_fn = self.make_pth("\n\n  \n\n") | ||||||
|  |         known_paths = site.addpackage(pth_dir, pth_fn, set()) | ||||||
|  |         self.assertEqual(known_paths, set()) | ||||||
|  | 
 | ||||||
|     def test_addpackage_import_bad_pth_file(self): |     def test_addpackage_import_bad_pth_file(self): | ||||||
|         # Issue 5258 |         # Issue 5258 | ||||||
|         pth_dir, pth_fn = self.make_pth("abc\x00def\n") |         pth_dir, pth_fn = self.make_pth("abc\x00def\n") | ||||||
|  | @ -595,7 +601,6 @@ def test_startup_interactivehook_isolated_explicit(self): | ||||||
|             'import site, sys; site.enablerlcompleter(); sys.exit(hasattr(sys, "__interactivehook__"))']).wait() |             'import site, sys; site.enablerlcompleter(); sys.exit(hasattr(sys, "__interactivehook__"))']).wait() | ||||||
|         self.assertTrue(r, "'__interactivehook__' not added by enablerlcompleter()") |         self.assertTrue(r, "'__interactivehook__' not added by enablerlcompleter()") | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| @unittest.skipUnless(sys.platform == 'win32', "only supported on Windows") | @unittest.skipUnless(sys.platform == 'win32', "only supported on Windows") | ||||||
| class _pthFileTests(unittest.TestCase): | class _pthFileTests(unittest.TestCase): | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -0,0 +1,4 @@ | ||||||
|  | Ignore empty or whitespace-only lines in .pth files. This matches the | ||||||
|  | documentated behavior. Before, empty lines caused the site-packages | ||||||
|  | dir to appear multiple times in sys.path. | ||||||
|  | By Ido Michael, contributors Malcolm Smith and Tal Einat. | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 idomic
						idomic