473,385 Members | 1,402 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

Jun 3 '07 #1
2 1110
Gabriel Genellina <ga*******@yahoo.com.arwrote:
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
Jun 4 '07 #2
En Sun, 03 Jun 2007 21:35:05 -0300, Alex Martelli <al***@mac.comescribió:
>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

Jun 4 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Denis S. Otkidach | last post by:
I've noticed that the order of attribute lookup is inconsistent when descriptor is used. property instance takes precedence of instance attributes: >>> class A(object): .... def...
2
by: François Pinard | last post by:
This question is a bit technical, but hopefully, this list will offer me good hints or nice solutions. Happily enough for me, it often does! :-) I would need to recognise and play with...
14
by: Antoon Pardon | last post by:
Can anyone explain why descriptors only work when they are an attribute to an object or class. I think a lot of interesting things one can do with descriptors would be just as interesting if the...
8
by: David S. | last post by:
I am looking for a way to implement the same simple validation on many instance attributes and I thought descriptors (http://users.rcn.com/python/download/Descriptor.htm) looked like the right...
7
by: Dario | last post by:
I have an unmanaged library that handle many TCP/IP connections. In my .NET application i want to test if there is input available on these connections. Using an existing function of the unmanaged...
0
by: Steven Bethard | last post by:
Steven Bethard wrote: > (For anyone else out there reading who doesn't already know this, > Steven D'Aprano's comments are easily explained by noting that the > __get__ method of staticmethod...
12
by: bruno at modulix | last post by:
Hi I'm currently playing with some (possibly weird...) code, and I'd have a use for per-instance descriptors, ie (dummy code): class DummyDescriptor(object): def __get__(self, obj,...
0
by: jfigueiras | last post by:
>I have a problem with the module subprocess! As many other programs... I'm not sure what you mean by "non-standard file descriptors". The other program is free to open, read, write, etc any...
2
by: DJ Dharme | last post by:
Hi all, I am writing a multi-threaded application in c++ running on solaris. I have a file which is updated by a single thread by appending data into the file and at same time the other threads...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.