The type/object distinction and possible synthesis of OOP and imperative programming languages

Terry Jan Reedy tjreedy at udel.edu
Tue Apr 16 14:29:40 EDT 2013


On 4/16/2013 1:29 PM, Ethan Furman wrote:
> On 04/16/2013 01:25 AM, Serhiy Storchaka wrote:
>> On 16.04.13 07:46, Ian Kelly wrote:
>>> On Mon, Apr 15, 2013 at 9:17 PM, Terry Jan Reedy <tjreedy at udel.edu>
>>> wrote:
>>>> I will keep the above in mind if I write or review a patch. here are 4
>>>> non-subclassable builtin classes. Two are already documented. Bool
>>>> in one,
>>>> forget which other. I believe it was recently decided to leave the
>>>> other two
>>>> as is given the absence of any practical use case.
>>>
>>> The four are bool, NoneType, slice and ellipsis, I believe.
>>
>> --> import builtins
>> --> for n in dir(builtins):
>> ...     if type(getattr(builtins, n)) is type:
>> ...         try:
>> ...             t = type(n, (getattr(builtins, n),), {})
>> ...         except TypeError as e:
>> ...             print(e)
>> ...
>> type 'bool' is not an acceptable base type
>> type 'memoryview' is not an acceptable base type
>> type 'range' is not an acceptable base type
>> type 'slice' is not an acceptable base type
>
> Well that bumps our count to five then:
>
> --> NoneType = type(None)
> --> NoneType
> <class 'NoneType'>
> --> class MoreNone(NoneType):
> ...   pass
> ...
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
> TypeError: type 'NoneType' is not an acceptable base type

'NoneType' is not a builtin name in builtins, which is precisely why you 
accessed it the way you did ;-). From issue 17279 (for 3.3):

"Attached subclassable.py produces these lists:
Among named builtin classes, these cannot be subclassed:
bool, memoryview, range, slice,
Among types classes, these can be subclassed:
ModuleType, SimpleNamespace,"






More information about the Python-list mailing list