-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[C API] Add PyUnicode_Equal() function #124502
Comments
I think |
The C API Guidelines suggest to return 1 if "found" and 0 if "not found": https://devguide.python.org/developer-workflow/c-api/#guidelines-for-expanding-changing-the-public-api IMO it's more natural to return 1 if equal and 0 if not equal. So you can write Moreover, |
I think that's good idea, So when will it be implemented? |
I already implemented the function. See attached PR. |
Hmm, will this result in a cascade of Out of curiosity, what's the benefit here over |
|
C extensions such as mypy and Pyodide are already using the private I'm not aware of other PyTYPE_Equal() function. Only PyUnicode has a specialized equal function.
|
Yeah, that's what I mean. I think it would be a bad idea to use this as precedent for future "faster" |
I created capi-workgroup/decisions#43 issue in the C API Working Group. |
* Replace unicode_compare_eq() with unicode_eq(). * Replace _PyUnicode_EQ() calls with _PyUnicode_Equal(). * Remove _PyUnicode_EQ().
* Cleanup unicode_compare_eq() code. * Copy unicode_compare_eq() code in unicode_eq(): the two functions are now identical.
* Replace _PyUnicode_EQ() with _PyUnicode_Equal(). * Replace unicode_compare_eq() with unicode_eq(). * Remove unicode_compare_eq() and _PyUnicode_EQ().
* Replace unicode_compare_eq() with unicode_eq(). * Replace _PyUnicode_EQ() with _PyUnicode_Equal(). * Remove unicode_compare_eq() and _PyUnicode_EQ().
* Replace unicode_compare_eq() with unicode_eq(). * Use unicode_eq() in setobject.c. * Replace _PyUnicode_EQ() with _PyUnicode_Equal(). * Remove unicode_compare_eq() and _PyUnicode_EQ().
Function added by change a7f0727. |
Function added to pythoncapi-compat with change: python/pythoncapi-compat@abc0f29. |
* Replace unicode_compare_eq() with unicode_eq(). * Use unicode_eq() in setobject.c. * Replace _PyUnicode_EQ() with _PyUnicode_Equal(). * Remove unicode_compare_eq() and _PyUnicode_EQ().
Use functions added for Python 3.14 * `PyBytes_Join` added in python/cpython#121645 * `PyUnicode_Equal` added in python/cpython#124502
Use functions added for Python 3.14 * `PyBytes_Join` added in python/cpython#121645 * `PyUnicode_Equal` added in python/cpython#124502
Python 3.13 moved the private _PyUnicode_EQ() function to internal C API. mypy and Pyodide are using it.
I propose to add a public PyUnicode_Equal(a, b) function to the limited C API 3.14 to replace the private _PyUnicode_EQ() function:
1
if a is equal to b.0
if a is not equal to b.TypeError
exception and return-1
if a or b is not a Pythonstr
object.Linked PRs
The text was updated successfully, but these errors were encountered: