On Sep 3, 2014, at 12:55 AM, Wolfgang Rohdewald <wolfgang....@rohdewald.de> 
wrote:

> Am Mittwoch, 3. September 2014, 00:29:59 schrieb Glyph:
>>> That is my problem. How do I know if the object is of a non-class class?
>> 
>> isinstance(something, (types.ClassType, type)).
> 
> but that will make it possible to attach a method even to type "int"

Yes, that's fine.  'int' has methods, there's no reason that those methods 
couldn't be serialized by jelly.  For example:

>>> (3).conjugate
<built-in method conjugate of int object at 0x7feb18410a78>

The bound method object there is the sort of thing that we're talking about.

Particularly since we might be talking about a subclass of 'int' with its own 
overridden conjugate method, and the im_class attribute says which class the 
method's function actually came from.

> Python2:
> 
>>>> isinstance(int, type)
> True
> 
>>>>> isinstance(object, type)
>> True
>>>>> isinstance(object(), type)
>> False

> Sure but the test only gets the class and it should certainly not instantiate 
> it.

Right; the point is that you get a thing, and that thing may be a class object 
_or_ it might be an instance object, and if it's an instance that's invalid.

> Meanwhile I believe it is best to simply remove the test since python itself
> will reject most:
> 
>>>> a=int
>>>> a.x=5
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> TypeError: can't set attributes of built-in/extension type 'int'

This is about serializing and deserializing existing methods, not assigning 
attributes to instances.

-glyph

_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Reply via email to