<br><br><div class="gmail_quote">On Sat, Mar 3, 2012 at 13:12, Stefan Behnel <span dir="ltr">&lt;<a href="mailto:stefan_ml@behnel.de">stefan_ml@behnel.de</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thomas Wouters, 03.03.2012 21:59:<br>
<div class="im">&gt; Why even have separate tp_as_sequence and tp_as_mapping anymore? That<br>
&gt; particular distinction never existed for Python types, so why should it<br>
&gt; exist for C types at all? I forget if there was ever a real point to it,<br>
&gt; but all it seems to do now is create confusion, what with many sequence<br>
&gt; types implementing both, and PyMapping_Check() and PySequence_Check() doing<br>
&gt; seemingly random things to come up with somewhat sensible answers. Do note<br>
&gt; that the dict type actually implements tp_as_sequence (in order to support<br>
&gt; containtment tests) and that PySequence_Check() has to explicitly return 0<br>
&gt; for dicts -- which means that it will give the &quot;wrong&quot; answer for another<br>
&gt; type that behaves exactly like dicts.<br>
&gt;<br>
&gt; Getting rid of the misleading distinction seems like a much better idea<br>
&gt; than trying to re-conflate some of the issues.<br>
<br>
</div>We&#39;re too far away from the release of Python 4 to change something with<br>
that kind of impact, though.</blockquote><div><br></div><div>It&#39;s not hard to do this in a backward-compatible way. Either grow one of the tp_as_* to include everything a &#39;unified&#39; tp_as_everything struct would need, or add a new tp_as_everything slot in the type struct. Then add a tp_flag to indicate that the type has this new layout/slot and guard all uses of the new slots with a check for that flag. If the type doesn&#39;t have the new layout or doesn&#39;t have it or the slots in it set, the code can fall back to the old try-one-and-then-the-other behaviour of dealing with tp_as_sequence and tp_as_mapping. </div>
</div><div><br></div><div>(Let&#39;s not forget about tp_as_sequence.sq_concat, tp_as_number.nb_add, tp_as_sequence.sq_repeat and tp_as_number.nb_mul either.)</div><div><br></div>-- <br>Thomas Wouters &lt;<a href="mailto:thomas@python.org">thomas@python.org</a>&gt;<br>
<br>Hi! I&#39;m a .signature virus! copy me into your .signature file to help me spread!<br>

AltStyle によって変換されたページ (->オリジナル) /