| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 551f8e1 commit a5568d0
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -411,6 +411,11 @@ def test_mapping_getoptionalitem(self): | |||
| 411 | 411 | self.assertEqual(getitem(dct2, 'a'), 1) | |
| 412 | 412 | self.assertEqual(getitem(dct2, 'b'), KeyError) | |
| 413 | 413 | ||
| 414 | + frozendct = frozendict(dct) | ||
| 415 | + self.assertEqual(getitem(frozendct, 'a'), 1) | ||
| 416 | + self.assertEqual(getitem(frozendct, 'b'), KeyError) | ||
| 417 | + self.assertEqual(getitem(frozendct, '\U0001f40d'), 2) | ||
| 418 | + | ||
| 414 | 419 | self.assertEqual(getitem(['a', 'b', 'c'], 1), 'b') | |
| 415 | 420 | ||
| 416 | 421 | self.assertRaises(TypeError, getitem, 42, 'a') | |
@@ -431,6 +436,11 @@ def test_mapping_getoptionalitemstring(self): | |||
| 431 | 436 | self.assertEqual(getitemstring(dct2, b'a'), 1) | |
| 432 | 437 | self.assertEqual(getitemstring(dct2, b'b'), KeyError) | |
| 433 | 438 | ||
| 439 | + frozendct = frozendict(dct) | ||
| 440 | + self.assertEqual(getitemstring(frozendct, 'a'), 1) | ||
| 441 | + self.assertEqual(getitemstring(frozendct, 'b'), KeyError) | ||
| 442 | + self.assertEqual(getitemstring(frozendct, '\U0001f40d'.encode()), 2) | ||
| 443 | + | ||
| 434 | 444 | self.assertRaises(TypeError, getitemstring, 42, b'a') | |
| 435 | 445 | self.assertRaises(UnicodeDecodeError, getitemstring, {}, b'\xff') | |
| 436 | 446 | self.assertRaises(SystemError, getitemstring, {}, NULL) | |
@@ -677,8 +687,10 @@ def items(self): | |||
| 677 | 687 | dict_obj = {'foo': 1, 'bar': 2, 'spam': 3} | |
| 678 | 688 | ||
| 679 | 689 | for mapping in [{}, OrderedDict(), Mapping1(), Mapping2(), | |
| 690 | + frozendict(), | ||
| 680 | 691 | dict_obj, OrderedDict(dict_obj), | |
| 681 | - Mapping1(dict_obj), Mapping2(dict_obj)]: | ||
| 692 | + Mapping1(dict_obj), Mapping2(dict_obj), | ||
| 693 | + frozendict(dict_obj)]: | ||
| 682 | 694 | self.assertListEqual(_testlimitedcapi.mapping_keys(mapping), | |
| 683 | 695 | list(mapping.keys())) | |
| 684 | 696 | self.assertListEqual(_testlimitedcapi.mapping_values(mapping), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + Add :class:`frozendict` to the fast paths of :c:func:`PyMapping_GetOptionalItem`, :c:func:`PyMapping_Keys`, :c:func:`PyMapping_Values`, and :c:func:`PyMapping_Items`. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -208,7 +208,7 @@ PyObject_GetItem(PyObject *o, PyObject *key) | |||
| 208 | 208 | int | |
| 209 | 209 | PyMapping_GetOptionalItem(PyObject *obj, PyObject *key, PyObject **result) | |
| 210 | 210 | { | |
| 211 | - if (PyDict_CheckExact(obj)) { | ||
| 211 | + if (PyAnyDict_CheckExact(obj)) { | ||
| 212 | 212 | return PyDict_GetItemRef(obj, key, result); | |
| 213 | 213 | } | |
| 214 | 214 | ||
@@ -2462,7 +2462,7 @@ PyMapping_Keys(PyObject *o) | |||
| 2462 | 2462 | if (o == NULL) { | |
| 2463 | 2463 | return null_error(); | |
| 2464 | 2464 | } | |
| 2465 | - if (PyDict_CheckExact(o)) { | ||
| 2465 | + if (PyAnyDict_CheckExact(o)) { | ||
| 2466 | 2466 | return PyDict_Keys(o); | |
| 2467 | 2467 | } | |
| 2468 | 2468 | return method_output_as_list(o, &_Py_ID(keys)); | |
@@ -2474,7 +2474,7 @@ PyMapping_Items(PyObject *o) | |||
| 2474 | 2474 | if (o == NULL) { | |
| 2475 | 2475 | return null_error(); | |
| 2476 | 2476 | } | |
| 2477 | - if (PyDict_CheckExact(o)) { | ||
| 2477 | + if (PyAnyDict_CheckExact(o)) { | ||
| 2478 | 2478 | return PyDict_Items(o); | |
| 2479 | 2479 | } | |
| 2480 | 2480 | return method_output_as_list(o, &_Py_ID(items)); | |
@@ -2486,7 +2486,7 @@ PyMapping_Values(PyObject *o) | |||
| 2486 | 2486 | if (o == NULL) { | |
| 2487 | 2487 | return null_error(); | |
| 2488 | 2488 | } | |
| 2489 | - if (PyDict_CheckExact(o)) { | ||
| 2489 | + if (PyAnyDict_CheckExact(o)) { | ||
| 2490 | 2490 | return PyDict_Values(o); | |
| 2491 | 2491 | } | |
| 2492 | 2492 | return method_output_as_list(o, &_Py_ID(values)); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments