mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 21:51:50 +00:00 
			
		
		
		
	#2346/#2347: add py3k warning for __methods__ and __members__. Patch by Jack Diederich.
This commit is contained in:
		
							parent
							
								
									5a44424c5e
								
							
						
					
					
						commit
						07e5681fd3
					
				
					 4 changed files with 30 additions and 1 deletions
				
			
		|  | @ -99,6 +99,16 @@ def test_sys_exc_clear(self): | ||||||
|         with catch_warning() as w: |         with catch_warning() as w: | ||||||
|             self.assertWarning(sys.exc_clear(), w, expected) |             self.assertWarning(sys.exc_clear(), w, expected) | ||||||
| 
 | 
 | ||||||
|  |     def test_methods_members(self): | ||||||
|  |         expected = '__members__ and __methods__ not supported in 3.x' | ||||||
|  |         class C: | ||||||
|  |             __methods__ = ['a'] | ||||||
|  |             __members__ = ['b'] | ||||||
|  |         c = C() | ||||||
|  |         with catch_warning() as w: | ||||||
|  |             self.assertWarning(dir(c), w, expected) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| def test_main(): | def test_main(): | ||||||
|     run_unittest(TestPy3KWarnings) |     run_unittest(TestPy3KWarnings) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -12,6 +12,8 @@ What's New in Python 2.6 alpha 2? | ||||||
| Core and builtins | Core and builtins | ||||||
| ----------------- | ----------------- | ||||||
|   |   | ||||||
|  | - Issue #2346/#2347: add Py3k warnings for __methods__ and __members__. | ||||||
|  | 
 | ||||||
| - Issue #2358: Add a Py3k warning on sys.exc_clear() usage. | - Issue #2358: Add a Py3k warning on sys.exc_clear() usage. | ||||||
| 
 | 
 | ||||||
| - Issue #2400: Allow relative imports to "import *". | - Issue #2400: Allow relative imports to "import *". | ||||||
|  |  | ||||||
|  | @ -352,8 +352,15 @@ PyObject * | ||||||
| Py_FindMethodInChain(PyMethodChain *chain, PyObject *self, const char *name) | Py_FindMethodInChain(PyMethodChain *chain, PyObject *self, const char *name) | ||||||
| { | { | ||||||
| 	if (name[0] == '_' && name[1] == '_') { | 	if (name[0] == '_' && name[1] == '_') { | ||||||
| 		if (strcmp(name, "__methods__") == 0) | 		if (strcmp(name, "__methods__") == 0) { | ||||||
|  | 			if (Py_Py3kWarningFlag) { | ||||||
|  | 				if (PyErr_Warn(PyExc_DeprecationWarning, | ||||||
|  | 					       "__methods__ not supported " | ||||||
|  | 					       "in 3.x") < 0) | ||||||
|  | 					return NULL; | ||||||
|  | 			} | ||||||
| 			return listmethodchain(chain); | 			return listmethodchain(chain); | ||||||
|  | 		} | ||||||
| 		if (strcmp(name, "__doc__") == 0) { | 		if (strcmp(name, "__doc__") == 0) { | ||||||
| 			const char *doc = self->ob_type->tp_doc; | 			const char *doc = self->ob_type->tp_doc; | ||||||
| 			if (doc != NULL) | 			if (doc != NULL) | ||||||
|  |  | ||||||
|  | @ -1687,6 +1687,16 @@ merge_list_attr(PyObject* dict, PyObject* obj, const char *attrname) | ||||||
| 					break; | 					break; | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  | 		if (Py_Py3kWarningFlag && | ||||||
|  | 		    (strcmp(attrname, "__members__") == 0 || | ||||||
|  | 		     strcmp(attrname, "__methods__") == 0)) { | ||||||
|  | 			if (PyErr_Warn(PyExc_DeprecationWarning,  | ||||||
|  | 				       "__members__ and __methods__ not supported " | ||||||
|  | 				       "in 3.x") < 0) { | ||||||
|  | 				Py_XDECREF(list); | ||||||
|  | 				return -1; | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	Py_XDECREF(list); | 	Py_XDECREF(list); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Georg Brandl
						Georg Brandl