mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Fix problem discovered by Greg McFarlane: when an imported module
replaces its own entry in sys.module, reference count errors ensue; even if there is no reference count problem, it would be preferable for the import to yield the new thing in sys.modules anyway (if only because that's what later imports will yield). This opens the road to an official hack to implement a __getattr__ like feature for modules: stick an instance in sys.modules[__name__].
This commit is contained in:
		
							parent
							
								
									e6648967b7
								
							
						
					
					
						commit
						b65e85cb73
					
				
					 1 changed files with 7 additions and 0 deletions
				
			
		|  | @ -182,6 +182,13 @@ PyImport_ExecCodeModule(name, co) | |||
| 	if (v == NULL) | ||||
| 		return NULL; | ||||
| 	Py_DECREF(v); | ||||
| 
 | ||||
| 	if ((m = PyDict_GetItemString(_PyImport_Modules, name)) == NULL) { | ||||
| 		PyErr_SetString(PyExc_SystemError, | ||||
| 				"loaded module not found in sys.modules"); | ||||
| 		return NULL; | ||||
| 	} | ||||
| 
 | ||||
| 	Py_INCREF(m); | ||||
| 
 | ||||
| 	return m; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Guido van Rossum
						Guido van Rossum