mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	Add a default __prepare__() method to 'type', so it can be called
using super(). (See recent conversation on python-3000 with Talin and Phillip Eby about PEP 3115 chaining rules.)
This commit is contained in:
		
							parent
							
								
									a9efc8e268
								
							
						
					
					
						commit
						4737482fad
					
				
					 2 changed files with 33 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -207,6 +207,29 @@
 | 
			
		|||
    kw: [('other', 'booh')]
 | 
			
		||||
    >>>
 | 
			
		||||
 | 
			
		||||
The default metaclass must define a __prepare__() method.
 | 
			
		||||
 | 
			
		||||
    >>> type.__prepare__()
 | 
			
		||||
    {}
 | 
			
		||||
    >>>
 | 
			
		||||
 | 
			
		||||
Make sure it works with subclassing.
 | 
			
		||||
 | 
			
		||||
    >>> class M(type):
 | 
			
		||||
    ...     @classmethod
 | 
			
		||||
    ...     def __prepare__(cls, *args, **kwds):
 | 
			
		||||
    ...         d = super().__prepare__(*args, **kwds)
 | 
			
		||||
    ...         d["hello"] = 42
 | 
			
		||||
    ...         return d
 | 
			
		||||
    ...
 | 
			
		||||
    >>> class C(metaclass=M):
 | 
			
		||||
    ...     print(hello)
 | 
			
		||||
    ...
 | 
			
		||||
    42
 | 
			
		||||
    >>> print(C.hello)
 | 
			
		||||
    42
 | 
			
		||||
    >>>
 | 
			
		||||
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
__test__ = {'doctests' : doctests}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue