GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||
GeezerVison is showing github.com — bpo-43753: Add Py_Is() and Py_IsNone() functions by vstinner · Pull Request #25227 · python/cpython Conversation
|
|
I rebased my PR and I reimplemented Py_Is() as a macro. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
And I added unit tests. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@markshannon: so are you against the principle of adding this macro and using it? Or can I merge it? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@corona10 @serhiy-storchaka @methane @pitrou: Do you think that these 4 functions are useful? See https://bugs.python.org/issue43753 for the rationale. It's mostly about helping to write C extensions compatible with PyPy, and prepare the bright future of HPy. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Can this be added to the stable ABI even though it's a macro? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I don't see the point of adding it to the ABI in CPython right now. Can you please elaborate? I mostly care about the API. Raymond is concerned by the risk of a negative impact on performance: https://bugs.python.org/issue43753#msg390379 As I only care about the API, I'm perfectly fine with a macro. PyPy is free to implement it as a function if they want. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
But then people targetting the stable ABI can't use this API? If the goal is to maximize usage, then it should be part of the ABI... |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Ok, I get your point. That's why I declared Py_NewRef() and Py_XNewRef() as static inline functions and regular functions. I modified tests on these functions to test the macros (static inline functions) and the function implementations. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I prepared a pull request on my pythoncapi_compat project to add Py_Is(), Py_IsNone(), Py_IsTrue() and Py_IsFalse() to Python 3.9 and older and to PyPy: python/pythoncapi-compat#8 ;-) I will merge it if this PR is merged. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I am +1 on adding Py_Is(). It can be quite useful for some use-cases.
But other variations are not convinced to me.
If I understand your intention correctly, we may create all the variations of PyIsXXX for singleton objects. When considering adding is easy but deprecating and removing is hard, I would like to add Py_Is() API only.
if we add _Py_IsXXX variations as the private API, I am okay to add those :)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Ok.
I don't propose to add a variation for all singletons. Only for these 3 which are the common (None, True, False). I proposed Py_IsNone(), Py_IsTrue(), Py_IsFalse() to make the transition to Py_Is() more pleasant. IMO if we only add Py_Is(), it's harder to read code which repeat I removed Py_IsNone(), Py_IsTrue(), Py_IsFalse(). I also modified Python/ceval.c in this PR, so you can see the change in practice. So what do you prefer? Ony Py_Is() or with 4 functions? Example with the current C API: Only with Py_Is(): With Py_IsNone(), Py_IsTrue() and Py_IsFalse(): |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I think having the 4 functions is ok. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
After I wrote my comment with examples showing the 3 APIs, I changed my mind. I really want Py_IsNone(), Py_IsTrue(), Py_IsFalse(). Having to replace whereas replacing Even if the 3 functions are just helper, I would like to add them. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
"Py_IsTrue(x): Test if an object is True." Hum, I was confused by this description. I rewrote it mentioning the singleton word: => "Py_IsTrue(x): Test if an object is the True singleton." IMO the description now avoids any possible confusion with PyObject_IsTrue(x). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I am not super conviced. Why would people would like to use Py_Is if is going to be slower than just pointer comparison?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The intent is correctness if you care about other Python implelentations than CPython. If you don't care, well, don't use it :-)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think having the 4 functions is ok. x is None has been a recommended idiom for at least 20 years.
I don't propose to add a variation for all singletons. Only for these 3 which are the common (None, True, False).
I read the comments and I also change my mind to export those APIs.
So +1
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Add the Py_Is(x, y) function to test if the 'x' object is the 'y' object, the same as "x is y" in Python. Add also the Py_IsNone(), Py_IsTrue(), Py_IsFalse() functions to test if an object is, respectively, the None singleton, the True singleton or the False singleton.
|
@pablogsal: Oh, thank you for fixing my English :-) I addressed your review. About exposing Py_Is() and Py_IsNone() as a regular function: please see @pitrou's previous comment. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
The docs CI failed with: Does anyone understand what's wrong with my NEWS entry? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I think this warning was due to #25335 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Oh ok. I merged my PR in this case. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @erlend-aasland @pitrou @corona10 and @pablogsal for your useful reviews! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
The upgrade_pythoncapi.py script performs transforms on C extension
sources to use new syntax [0]. It's generally used with a shim header
for compatibility, but the header is not necessary for these changes.
The suggested changes are:
* Use the `Py_IsNone` function introduced in CPython 3.10 [1] over
direct comparison to `Py_None`.
* Use `PyObject_Free` instead of `PyObject_Del` since `PyObject_Del`
has been aliased to `PyObject_Free` for nearly 24 years [2] and has
been announced as deprecated [3].
[0]: https://pythoncapi-compat.readthedocs.io/en/latest/index.html
[1]: python/cpython#25227
[2]: python/cpython@3e7b893
[3]: https://docs.python.org/3/c-api/allocation.html#deprecated-aliases
Signed-off-by: Vincent Fazio <[email protected]>
The upgrade_pythoncapi.py script performs transforms on C extension
sources to use new syntax [0]. It's generally used with a shim header
for compatibility, but the header is not necessary for these changes.
The suggested changes are:
* Use the `Py_IsNone` function introduced in CPython 3.10 [1] over
direct comparison to `Py_None`.
* Use `PyObject_Free` instead of `PyObject_Del` since `PyObject_Del`
has been aliased to `PyObject_Free` for nearly 24 years [2] and has
been announced as deprecated [3].
[0]: https://pythoncapi-compat.readthedocs.io/en/latest/index.html
[1]: python/cpython#25227
[2]: python/cpython@3e7b893
[3]: https://docs.python.org/3/c-api/allocation.html#deprecated-aliases
Signed-off-by: Vincent Fazio <[email protected]>
The upgrade_pythoncapi.py script performs transforms on C extension
sources to use new syntax [0]. It's generally used with a shim header
for compatibility, but the header is not necessary for these changes.
The suggested changes are:
* Use the `Py_IsNone` function introduced in CPython 3.10 [1] over
direct comparison to `Py_None`.
* Use `PyObject_Free` instead of `PyObject_Del` since `PyObject_Del`
has been aliased to `PyObject_Free` for nearly 24 years [2] and has
been announced as deprecated [3].
[0]: https://pythoncapi-compat.readthedocs.io/en/latest/index.html
[1]: python/cpython#25227
[2]: python/cpython@3e7b893
[3]: https://docs.python.org/3/c-api/allocation.html#deprecated-aliases
Signed-off-by: Vincent Fazio <[email protected]>
The upgrade_pythoncapi.py script performs transforms on C extension
sources to use new syntax [0]. It's generally used with a shim header
for compatibility, but the header is not necessary for these changes.
The suggested changes are:
* Use the `Py_IsNone` function introduced in CPython 3.10 [1] over
direct comparison to `Py_None`.
* Use `PyObject_Free` instead of `PyObject_Del` since `PyObject_Del`
has been aliased to `PyObject_Free` for nearly 24 years [2] and has
been announced as deprecated [3].
[0]: https://pythoncapi-compat.readthedocs.io/en/latest/index.html
[1]: python/cpython#25227
[2]: python/cpython@3e7b893
[3]: https://docs.python.org/3/c-api/allocation.html#deprecated-aliases
Signed-off-by: Vincent Fazio <[email protected]>
The upgrade_pythoncapi.py script performs transforms on C extension
sources to use new syntax [0]. It's generally used with a shim header
for compatibility, but the header is not necessary for these changes.
The suggested changes are:
* Use the `Py_IsNone` function introduced in CPython 3.10 [1] over
direct comparison to `Py_None`.
* Use `PyObject_Free` instead of `PyObject_Del` since `PyObject_Del`
has been aliased to `PyObject_Free` for nearly 24 years [2] and has
been announced as deprecated [3].
[0]: https://pythoncapi-compat.readthedocs.io/en/latest/index.html
[1]: python/cpython#25227
[2]: python/cpython@3e7b893
[3]: https://docs.python.org/3/c-api/allocation.html#deprecated-aliases
Signed-off-by: Vincent Fazio <[email protected]>
The upgrade_pythoncapi.py script performs transforms on C extension
sources to use new syntax [0]. It's generally used with a shim header
for compatibility, but the header is not necessary for these changes.
The suggested changes are:
* Use the `Py_IsNone` function introduced in CPython 3.10 [1] over
direct comparison to `Py_None`.
* Use `PyObject_Free` instead of `PyObject_Del` since `PyObject_Del`
has been aliased to `PyObject_Free` for nearly 24 years [2] and has
been announced as deprecated [3].
[0]: https://pythoncapi-compat.readthedocs.io/en/latest/index.html
[1]: python/cpython#25227
[2]: python/cpython@3e7b893
[3]: https://docs.python.org/3/c-api/allocation.html#deprecated-aliases
Signed-off-by: Vincent Fazio <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.