mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 21:51:50 +00:00 
			
		
		
		
	gh-123987: Fix NotADirectoryError in NamespaceReader when sentinel present (#124018)
This commit is contained in:
		
							parent
							
								
									fccbfc40b5
								
							
						
					
					
						commit
						b543b32eff
					
				
					 7 changed files with 93 additions and 18 deletions
				
			
		|  | @ -60,6 +60,26 @@ class OpenZipTests(FilesTests, util.ZipSetup, unittest.TestCase): | |||
| class OpenNamespaceTests(FilesTests, util.DiskSetup, unittest.TestCase): | ||||
|     MODULE = 'namespacedata01' | ||||
| 
 | ||||
|     def test_non_paths_in_dunder_path(self): | ||||
|         """ | ||||
|         Non-path items in a namespace package's ``__path__`` are ignored. | ||||
| 
 | ||||
|         As reported in python/importlib_resources#311, some tools | ||||
|         like Setuptools, when creating editable packages, will inject | ||||
|         non-paths into a namespace package's ``__path__``, a | ||||
|         sentinel like | ||||
|         ``__editable__.sample_namespace-1.0.finder.__path_hook__`` | ||||
|         to cause the ``PathEntryFinder`` to be called when searching | ||||
|         for packages. In that case, resources should still be loadable. | ||||
|         """ | ||||
|         import namespacedata01 | ||||
| 
 | ||||
|         namespacedata01.__path__.append( | ||||
|             '__editable__.sample_namespace-1.0.finder.__path_hook__' | ||||
|         ) | ||||
| 
 | ||||
|         resources.files(namespacedata01) | ||||
| 
 | ||||
| 
 | ||||
| class OpenNamespaceZipTests(FilesTests, util.ZipSetup, unittest.TestCase): | ||||
|     ZIP_MODULE = 'namespacedata01' | ||||
|  | @ -86,7 +106,7 @@ def test_module_resources(self): | |||
|         """ | ||||
|         A module can have resources found adjacent to the module. | ||||
|         """ | ||||
|         import mod | ||||
|         import mod  # type: ignore[import-not-found] | ||||
| 
 | ||||
|         actual = resources.files(mod).joinpath('res.txt').read_text(encoding='utf-8') | ||||
|         assert actual == self.spec['res.txt'] | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Jason R. Coombs
						Jason R. Coombs