[issue43753] [C API] Add Py_Is(x, y) and Py_IsNone(x) functions

2021-09-29 Thread STINNER Victor
STINNER Victor added the comment: New changeset 8d3e7eff0936926554db6162c992af5829dc8160 by Victor Stinner in branch 'main': bpo-43753: _operator.is_() uses Py_Is() (GH-28641) https://github.com/python/cpython/commit/8d3e7eff0936926554db6162c992af5829dc8160 --

[issue43753] [C API] Add Py_Is(x, y) and Py_IsNone(x) functions

2021-09-29 Thread STINNER Victor
Change by STINNER Victor : -- pull_requests: +27009 pull_request: https://github.com/python/cpython/pull/28641 ___ Python tracker ___

[issue43753] [C API] Add Py_Is(x, y) and Py_IsNone(x) functions

2021-05-18 Thread STINNER Victor
STINNER Victor added the comment: Well, nobody came up with a better definition, so let's go with: "Test if the x object is the y object, the same as x is y in Python." Thanks for the feedback and reviews! Py_Is(x, y), Py_IsNone(x), Py_IsTrue(x) and Py_IsFalse(x) are now part of Python 3.10

[issue43753] [C API] Add Py_Is(x, y) and Py_IsNone(x) functions

2021-04-10 Thread STINNER Victor
STINNER Victor added the comment: Carl: > Just chiming in to say that for PyPy this API would be extremely useful, > because PyPy's "is" is not implementable with a pointer comparison on the C > level (due to unboxing we need to compare integers, floats, etc by value). > Right now, C

[issue43753] [C API] Add Py_Is(x, y) and Py_IsNone(x) functions

2021-04-10 Thread STINNER Victor
STINNER Victor added the comment: New changeset 09bbebea163fe7303264cf4069c51d4d2f22fde4 by Victor Stinner in branch 'master': bpo-43753: Add Py_Is() and Py_IsNone() functions (GH-25227) https://github.com/python/cpython/commit/09bbebea163fe7303264cf4069c51d4d2f22fde4 --

[issue43753] [C API] Add Py_Is(x, y) and Py_IsNone(x) functions

2021-04-09 Thread STINNER Victor
STINNER Victor added the comment: > I tried applying this API on an extension, and I found the code to be > slightly less readable for the "is not" cases. FYI you can try upgrade_pythoncapi.py on your project using the following PR to update code to use Py_IsNone/Py_IsTrue/Py_IsFalse:

[issue43753] [C API] Add Py_Is(x, y) and Py_IsNone(x) functions

2021-04-09 Thread Erlend Egeberg Aasland
Erlend Egeberg Aasland added the comment: > I would prefer keep the C API small. Yes, I see the value of that as well. I tried applying this API on an extension, and I found the code to be slightly less readable for the "is not" cases. -- ___

[issue43753] [C API] Add Py_Is(x, y) and Py_IsNone(x) functions

2021-04-09 Thread STINNER Victor
STINNER Victor added the comment: > I'd also prefer a Py_IsNotNone() because it's more explicit than !Py_IsNone() I would prefer keep the C API small. I don't think that we need to duplicate all functions testing for something. We provide PyTuple_Check(obj) but we don't provide

[issue43753] [C API] Add Py_Is(x, y) and Py_IsNone(x) functions

2021-04-09 Thread Erlend Egeberg Aasland
Erlend Egeberg Aasland added the comment: I'd also prefer a Py_IsNotNone() because it's more explicit than !Py_IsNone(); the exclamation mark can be easily missed when reading/writing code, IMO. Just my 2 cents. -- nosy: +erlendaasland ___ Python

[issue43753] [C API] Add Py_Is(x, y) and Py_IsNone(x) functions

2021-04-08 Thread STINNER Victor
STINNER Victor added the comment: Mark: > `is` is not well defined except for a small set of values, so the docs for > `Py_Is` would have to so vague as to be worthless, IMO. I don't propose to change the "is" operator semantic: Py_Is(x, y) is C would behave *exaclty* as "x is y" in Python.

[issue43753] [C API] Add Py_Is(x, y) and Py_IsNone(x) functions

2021-04-07 Thread STINNER Victor
STINNER Victor added the comment: PR 25227: I reimplemented Py_Is() as a macro and I added unit tests. Other added functions simply call Py_Is(), example: #define Py_IsNone(x) Py_Is(x, Py_None) -- ___ Python tracker

[issue43753] [C API] Add Py_Is(x, y) and Py_IsNone(x) functions

2021-04-07 Thread Raymond Hettinger
Raymond Hettinger added the comment: > Just chiming in to say that for PyPy this API would be extremely useful Thanks for that input. Given that there would be some value add, I withdraw my objection. > I proposed to declare it as a "static inline" function, > but I'm fine with a macro as

[issue43753] [C API] Add Py_Is(x, y) and Py_IsNone(x) functions

2021-04-07 Thread Carl Friedrich Bolz-Tereick
Carl Friedrich Bolz-Tereick added the comment: Just chiming in to say that for PyPy this API would be extremely useful, because PyPy's "is" is not implementable with a pointer comparison on the C level (due to unboxing we need to compare integers, floats, etc by value). Right now, C

[issue43753] [C API] Add Py_Is(x, y) and Py_IsNone(x) functions

2021-04-07 Thread STINNER Victor
STINNER Victor added the comment: > Also, there is too much faith in functions marked as "inline" always being > inlined. I proposed to declare it as a "static inline" function, but I'm fine with a macro as well. I mostly care about the API: call "Py_Is()", not really about the exact

[issue43753] [C API] Add Py_Is(x, y) and Py_IsNone(x) functions

2021-04-07 Thread STINNER Victor
STINNER Victor added the comment: > For any sane design of tagged pointers, `x == y` (in C) will work fine. I wrote a proof-of-concept for using tagged pointners in CPython: https://github.com/vstinner/cpython/pull/6 "The PR is large because of the first changes which add Py_IS_NONE(),

[issue43753] [C API] Add Py_Is(x, y) and Py_IsNone(x) functions

2021-04-07 Thread Mark Shannon
Mark Shannon added the comment: For any sane design of tagged pointers, `x == y` (in C) will work fine. `is` is not well defined except for a small set of values, so the docs for `Py_Is` would have to so vague as to be worthless, IMO. -- nosy: +Mark.Shannon

[issue43753] [C API] Add Py_Is(x, y) and Py_IsNone(x) functions

2021-04-07 Thread Mark Dickinson
Change by Mark Dickinson : -- nosy: +mark.dickinson ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue43753] [C API] Add Py_Is(x, y) and Py_IsNone(x) functions

2021-04-06 Thread hai shi
Change by hai shi : -- nosy: +shihai1991 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue43753] [C API] Add Py_Is(x, y) and Py_IsNone(x) functions

2021-04-06 Thread Raymond Hettinger
Change by Raymond Hettinger : -- nosy: +pablogsal, tim.peters ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue43753] [C API] Add Py_Is(x, y) and Py_IsNone(x) functions

2021-04-06 Thread Raymond Hettinger
Raymond Hettinger added the comment: > Right now, there is no benefit for CPython. Please don't this until we have a clear demonstrable benefit. As it stands now, this is all cost and no benefit. Adding unnecessary abstraction layers just makes it more difficult for people to learn to be

[issue43753] [C API] Add Py_Is(x, y) and Py_IsNone(x) functions

2021-04-06 Thread STINNER Victor
STINNER Victor added the comment: Py_IS_TYPE(obj, type) was added to Python 3.9 by bpo-39573: https://docs.python.org/dev/c-api/structures.html#c.Py_IS_TYPE commit d905df766c367c350f20c46ccd99d4da19ed57d8 Author: Dong-hee Na Date: Fri Feb 14 02:37:17 2020 +0900 bpo-39573: Add

[issue43753] [C API] Add Py_IS(x, y) and Py_IsNone(x) functions

2021-04-06 Thread STINNER Victor
Change by STINNER Victor : -- title: [C API] Add Py_IS(x, y) macro -> [C API] Add Py_IS(x, y) and Py_IsNone(x) functions ___ Python tracker ___

[issue43753] [C API] Add Py_Is(x, y) and Py_IsNone(x) functions

2021-04-06 Thread STINNER Victor
Change by STINNER Victor : -- title: [C API] Add Py_IS(x, y) and Py_IsNone(x) functions -> [C API] Add Py_Is(x, y) and Py_IsNone(x) functions ___ Python tracker ___