[Python-Dev] PEP: Consolidating names and classes in the `unittest` module

Steve Holden steve at holdenweb.com
Tue Jul 15 08:21:01 CEST 2008


Michael Foord wrote:
> Benjamin Peterson wrote:
>> On Mon, Jul 14, 2008 at 6:18 PM, Ben Finney 
>> <ben+python at benfinney.id.au> wrote:
>>  
>>> "Benjamin Peterson" <musiccomposition at gmail.com> writes:
>>>
>>>    
>>>> On Mon, Jul 14, 2008 at 8:25 AM, Ben Finney 
>>>> <ben+python at benfinney.id.au> wrote:
>>>>      
>>>>> Use new-style classes throughout
>>>>> --------------------------------
>>>>>
>>>>> The following classes will inherit explicitly from the built-in
>>>>> `object` type, to make all classes in the module part of the new-style
>>>>> type hierarchy.
>>>>>
>>>>> * ``TestResult``
>>>>> * ``TestCase``
>>>>> * ``TestSuite``
>>>>> * ``TestLoader``
>>>>> * ``_WritelnDecorator``
>>>>> * ``TextTestRunner``
>>>>> * ``TestProgram``
>>>>>         
>>>> They already do. __metaclass__ = type is found in unittest.py.
>>>>       
>>> Not in the copy I have. Is that in 3.x only, or in 2.x also?
>>>     
>>
>> Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53)
>> [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
>> Type "help", "copyright", "credits" or "license" for more information.
>>  
>>>>> import unittest
>>>>> isinstance(unittest.TestCase, object)
>>>>>         
>> True
>>
>>
>>   
> That proves nothing:
> 
> Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53)
> [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> class x: pass
> ...
>  >>> isinstance(x, object)
> True
>  >>> isinstance(x, type)
> False
>  >>> type(x)
> <type 'classobj'>
> 
Shouldn't isinstance(x, object) be True for any x in recent CPythons 
(and hopefully the other implementations too)? It's certainly so for 
functions and modules, for , as well as the less esoteric types and 
instances of classic classes.

Something that often ties students' heads in knots (and this isn't from 
the introductory course):

 >>> isinstance(type, object)
True
 >>> isinstance(object, type)
True

This is a classic property of general object hierarchies based on 
metaclasses. I remember teaching the SmallTalk-80 equivalent to M.Sc. 
studnets in the early 1980s, though the details are now lost in the 
mists of time. Eyes would always widen, and not everyone would get it.

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/



More information about the Python-Dev mailing list