| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -945,7 +945,7 @@ PyAPI_FUNC(PyObject*) _PyUnicode_FromId(_Py_Identifier*); | |||
| 945 | 945 | and where the hash values are equal (i.e. a very probable match) */ | |
| 946 | 946 | PyAPI_FUNC(int) _PyUnicode_EQ(PyObject *, PyObject *); | |
| 947 | 947 | ||
| 948 | - /* Equality check. Returns -1 on failure. */ | ||
| 948 | + /* Equality check. */ | ||
| 949 | 949 | PyAPI_FUNC(int) _PyUnicode_Equal(PyObject *, PyObject *); | |
| 950 | 950 | ||
| 951 | 951 | PyAPI_FUNC(int) _PyUnicode_WideCharString_Converter(PyObject *, void *); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1317,6 +1317,15 @@ class X(object): | |||
| 1317 | 1317 | with self.assertRaisesRegex(AttributeError, "'X' object has no attribute 'a'"): | |
| 1318 | 1318 | X().a | |
| 1319 | 1319 | ||
| 1320 | + # Test string subclass in `__slots__`, see gh-98783 | ||
| 1321 | + class SubStr(str): | ||
| 1322 | + pass | ||
| 1323 | + class X(object): | ||
| 1324 | + __slots__ = (SubStr('x'),) | ||
| 1325 | + X().x = 1 | ||
| 1326 | + with self.assertRaisesRegex(AttributeError, "'X' object has no attribute 'a'"): | ||
| 1327 | + X().a | ||
| 1328 | + | ||
| 1320 | 1329 | def test_slots_special(self): | |
| 1321 | 1330 | # Testing __dict__ and __weakref__ in __slots__... | |
| 1322 | 1331 | class D(object): | |
@@ -3589,6 +3598,16 @@ def __repr__(self): | |||
| 3589 | 3598 | self.assertEqual(o.__str__(), '41') | |
| 3590 | 3599 | self.assertEqual(o.__repr__(), 'A repr') | |
| 3591 | 3600 | ||
| 3601 | + def test_repr_with_module_str_subclass(self): | ||
| 3602 | + # gh-98783 | ||
| 3603 | + class StrSub(str): | ||
| 3604 | + pass | ||
| 3605 | + class Some: | ||
| 3606 | + pass | ||
| 3607 | + Some.__module__ = StrSub('example') | ||
| 3608 | + self.assertIsInstance(repr(Some), str) # should not crash | ||
| 3609 | + self.assertIsInstance(repr(Some()), str) # should not crash | ||
| 3610 | + | ||
| 3592 | 3611 | def test_keyword_arguments(self): | |
| 3593 | 3612 | # Testing keyword arguments to __init__, __call__... | |
| 3594 | 3613 | def f(a): return a | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1334,6 +1334,12 @@ def equivalent_python(n, length, byteorder, signed=False): | |||
| 1334 | 1334 | b'\xff\xff\xff\xff\xff') | |
| 1335 | 1335 | self.assertRaises(OverflowError, (1).to_bytes, 0, 'big') | |
| 1336 | 1336 | ||
| 1337 | + # gh-98783 | ||
| 1338 | + class SubStr(str): | ||
| 1339 | + pass | ||
| 1340 | + self.assertEqual((0).to_bytes(1, SubStr('big')), b'\x00') | ||
| 1341 | + self.assertEqual((0).to_bytes(0, SubStr('little')), b'') | ||
| 1342 | + | ||
| 1337 | 1343 | def test_from_bytes(self): | |
| 1338 | 1344 | def check(tests, byteorder, signed=False): | |
| 1339 | 1345 | def equivalent_python(byte_array, byteorder, signed=False): | |
@@ -1534,6 +1540,12 @@ def __bytes__(self): | |||
| 1534 | 1540 | self.assertRaises(TypeError, int.from_bytes, MissingBytes()) | |
| 1535 | 1541 | self.assertRaises(ZeroDivisionError, int.from_bytes, RaisingBytes()) | |
| 1536 | 1542 | ||
| 1543 | + # gh-98783 | ||
| 1544 | + class SubStr(str): | ||
| 1545 | + pass | ||
| 1546 | + self.assertEqual(int.from_bytes(b'', SubStr('big')), 0) | ||
| 1547 | + self.assertEqual(int.from_bytes(b'\x00', SubStr('little')), 0) | ||
| 1548 | + | ||
| 1537 | 1549 | @support.cpython_only | |
| 1538 | 1550 | def test_from_bytes_small(self): | |
| 1539 | 1551 | # bpo-46361 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Fix multiple crashes in debug mode when ``str`` subclasses | ||
| 2 | + are used instead of ``str`` itself. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10444,8 +10444,8 @@ unicode_compare_eq(PyObject *str1, PyObject *str2) | |||
| 10444 | 10444 | int | |
| 10445 | 10445 | _PyUnicode_Equal(PyObject *str1, PyObject *str2) | |
| 10446 | 10446 | { | |
| 10447 | - assert(PyUnicode_CheckExact(str1)); | ||
| 10448 | - assert(PyUnicode_CheckExact(str2)); | ||
| 10447 | + assert(PyUnicode_Check(str1)); | ||
| 10448 | + assert(PyUnicode_Check(str2)); | ||
| 10449 | 10449 | if (str1 == str2) { | |
| 10450 | 10450 | return 1; | |
| 10451 | 10451 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments