Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Python Programming Language

Check for descriptors (in C)


For most types, there are macros like PyXxxx_Check and
PyXxxx_CheckExact. But not for descriptors, and I want to test if a
certain object is a descriptor or not. May I define
PyMethodDescr_Check, by example, along the lines of similar checks, or
the fact that they are not already defined implies that they should
not be tested that way?

My actual use case: I want to check if an object (instance of a class
that inherits from file) still uses the original write method or has
overriden it.

--
Gabriel Genellina

Gabriel Genellina <gagsl-@yahoo.com.ar> wrote:
> For most types, there are macros like PyXxxx_Check and
> PyXxxx_CheckExact. But not for descriptors, and I want to test if a
> certain object is a descriptor or not. May I define
> PyMethodDescr_Check, by example, along the lines of similar checks, or
> the fact that they are not already defined implies that they should
> not be tested that way?

"Being a descriptor" == "belonging to a type having a __get__ method",
more or less. There is NO relationship among such types, just a
commonality of methods they make available. Descriptor is a protocol,
common to a family of otherwise unrelated types, not a type. All of the
PyXXX_Check macros are instead based on *types*, not protocols.

> My actual use case: I want to check if an object (instance of a class
> that inherits from file) still uses the original write method or has
> overriden it.

I'd check for identity between type(o).write and file.write -- seems a
more direct expression of that thought (and implementable with the C-API
just as well as with pure Python).

Alex

En Sun, 03 Jun 2007 21:35:05 -0300, Alex Martelli <a@mac.com> escribi:

>> My actual use case: I want to check if an object (instance of a class
>> that inherits from file) still uses the original write method or has
>> overriden it.

> I'd check for identity between type(o).write and file.write -- seems a
> more direct expression of that thought (and implementable with the C-API
> just as well as with pure Python).

Thanks! It looks obvious now :)

--
Gabriel Genellina

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc