Message133026
| Author |
ncoghlan |
| Recipients |
Trundle, daniel.urban, eric.araujo, ncoghlan, pitrou, rhettinger |
| Date |
2011年04月05日.12:24:26 |
| SpamBayes Score |
6.547293e-10 |
| Marked as misclassified |
No |
| Message-id |
<1302006267.12.0.189797992305.issue10977@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
I may have found another use case for this functionality. Currently, the Python code in heapq.py accepts arbitrary sequences (that are sufficiently compatible with the Sequence ABC), but the C code in _heapq only permits use of a concrete list.
The two currently available approaches to address that discrepancy are:
1. Use PyObject_* calls instead of PyList_* calls throughout the code (yuck, we'd be making the common case significantly worse in the name of semantic purity)
2. Sprinkle type checks throughout the _heapq code to decide whether or not to call the concrete APIs or their abstract equivalents
The extensive use of the PyList macro API in _heapq means that a little bit of 2 might still be necessary even if the concrete API was updated as Raymond suggests, but I think there would be value in changing the meaning of the concrete APIs to include falling back to the abstract APIs if the type assumption is incorrect. |
|