This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2002年10月25日 21:35 by nascheme, last changed 2022年04月10日 16:05 by admin. This issue is now closed.
| Messages (7) | |||
|---|---|---|---|
| msg12941 - (view) | Author: Neil Schemenauer (nascheme) * (Python committer) | Date: 2002年10月25日 21:35 | |
I think PyNumber_Check should be deprecated. An type having tp_as_number does not mean it is a number. If we don't depreciate it, perhaps we should modify the test. For example, we could check for a __int__ method. Guido, if you decide what to do, assign the bug back to me and I will work on a patch. |
|||
| msg12942 - (view) | Author: Guido van Rossum (gvanrossum) * (Python committer) | Date: 2002年10月28日 02:39 | |
Logged In: YES user_id=6380 I agree that checking for tp_as_number is bogus. (Ditto for sequence and mapping -- are these similarly naive?) Is there any code that currently uses PyNumber_Check? Depending on what it is used for, I'd make a different decision. |
|||
| msg12943 - (view) | Author: Raymond Hettinger (rhettinger) * (Python committer) | Date: 2002年10月28日 13:10 | |
Logged In: YES user_id=80475 A grep of Modules, Objects, and Python shows that PyNumber_Check is only used in selectmodule.c The sequence and mapping checks are used much more frequently but not naively. They are used as guards before the slot is referenced. |
|||
| msg12944 - (view) | Author: Guido van Rossum (gvanrossum) * (Python committer) | Date: 2002年10月29日 23:02 | |
Logged In: YES user_id=6380 Adding a test for nb_int *or* nb_float would seem an adequate redefinition of PyNumber_Check(). But it's still not perfect -- a class instance *always* passes this test, for example, and you can get select() to report strange errors by passing a class instance. (And it also doesn't help for complex.) The problem is, what to use in the select module instead of PyNumber_Check()? There really isn't a decent alternative; we don't want to call PyInt_Check(), PyLong_Check() and PyFloat_Check() directly, and PyFloat_AsDouble() reports an unhelpful "bad argument type for built-in operation" when given a non-number. Hm, maybe PyFloat_AsDouble() should be changed to report a better error??? I've also noticed that at least some of the calls to PySequence_Check() seem bogus -- e.g. the ones in PySequence_List() and in list_fill() (which look like the same code BTW, as do several others). In fact, I think most (all?) uses of this should not be there, since they are only designed to give "nice" error messages, but they are neither necessary nor sufficient to catch all cases. (They aren't necessary because all the other PySequence_XXX() APIs do proper checking anyway.) I also noticed that PyMapping_Check() again gives a false sense of security in e.g. posix_execve(). |
|||
| msg12945 - (view) | Author: Neil Schemenauer (nascheme) * (Python committer) | Date: 2003年02月18日 17:50 | |
Logged In: YES user_id=35752 Progress update: Guido has changed PyNumber_Check() to check for nb_int and nb_float. I improved the PyFloat_AsDouble() exception message. Still need to check the usage of PySequence_Check() and PyMapping_Check(). |
|||
| msg12946 - (view) | Author: Neal Norwitz (nnorwitz) * (Python committer) | Date: 2005年10月02日 00:05 | |
Logged In: YES user_id=33168 Is this bug still valid? |
|||
| msg59316 - (view) | Author: Christian Heimes (christian.heimes) * (Python committer) | Date: 2008年01月05日 19:42 | |
Discuss the bug at the bug day. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月10日 16:05:47 | admin | set | github: 37367 |
| 2008年03月20日 21:25:56 | nascheme | set | status: open -> closed |
| 2008年01月05日 19:42:12 | christian.heimes | set | nosy:
+ christian.heimes type: enhancement messages: + msg59316 versions: + Python 2.6 |
| 2002年10月25日 21:35:20 | nascheme | create | |