Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-124502: Add PyUnicode_Equal() function#124504
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
81621294a2ae3d8953192ac057c6b5b30bf264de54File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1903,6 +1903,39 @@ def test_recover_error(self): | ||
| self.assertEqual(writer.finish(), 'Hello World.') | ||
| def test_unicode_equal(self): | ||
| unicode_equal = _testlimitedcapi.unicode_equal | ||
| def copy(text): | ||
| return text.encode().decode() | ||
| self.assertTrue(unicode_equal("", "")) | ||
| self.assertTrue(unicode_equal("abc", "abc")) | ||
| self.assertTrue(unicode_equal("abc", copy("abc"))) | ||
| self.assertTrue(unicode_equal("\u20ac", copy("\u20ac"))) | ||
| self.assertTrue(unicode_equal("\U0010ffff", copy("\U0010ffff"))) | ||
| self.assertFalse(unicode_equal("abc", "abcd")) | ||
| self.assertFalse(unicode_equal("\u20ac", "\u20ad")) | ||
| self.assertFalse(unicode_equal("\U0010ffff", "\U0010fffe")) | ||
| # str subclass | ||
| self.assertTrue(unicode_equal("abc", Str("abc"))) | ||
| self.assertTrue(unicode_equal(Str("abc"), "abc")) | ||
| self.assertFalse(unicode_equal("abc", Str("abcd"))) | ||
| self.assertFalse(unicode_equal(Str("abc"), "abcd")) | ||
| # invalid type | ||
| for invalid_type in (b'bytes', 123, ("tuple",)): | ||
| with self.subTest(invalid_type=invalid_type): | ||
| with self.assertRaises(TypeError): | ||
vstinner marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| unicode_equal("abc", invalid_type) | ||
| with self.assertRaises(TypeError): | ||
| unicode_equal(invalid_type, "abc") | ||
| # CRASHES unicode_equal("abc", NULL) | ||
| # CRASHES unicode_equal(NULL, "abc") | ||
| if __name__ == "__main__": | ||
| unittest.main() | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Add :c:func:`PyUnicode_Equal` function to the limited C API: test if two | ||
| strings are equal. Patch by Victor Stinner. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2536,3 +2536,5 @@ | ||
| added = '3.14' | ||
| [const.Py_TP_USE_SPEC] | ||
| added = '3.14' | ||
| [function.PyUnicode_Equal] | ||
| added = '3.14' | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -11001,6 +11001,24 @@ _PyUnicode_Equal(PyObject *str1, PyObject *str2) | ||
| } | ||
| int | ||
| PyUnicode_Equal(PyObject *str1, PyObject *str2) | ||
| { | ||
| if (!PyUnicode_Check(str1)){ | ||
| PyErr_Format(PyExc_TypeError, | ||
| "first argument must be str, not %T", str1); | ||
vstinner marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| return -1; | ||
| } | ||
| if (!PyUnicode_Check(str2)){ | ||
| PyErr_Format(PyExc_TypeError, | ||
| "second argument must be str, not %T", str2); | ||
| return -1; | ||
| } | ||
| return _PyUnicode_Equal(str1, str2); | ||
| } | ||
| int | ||
| PyUnicode_Compare(PyObject *left, PyObject *right) | ||
| { | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.