1. 05 May, 2001 7 commits
    • Tim Peters's avatar
      Remove redundant line. · 686cae7c
      Tim Peters authored
      686cae7c
    • Tim Peters's avatar
      Make 'x in y' and 'x not in y' (PySequence_Contains) play nice w/ iterators. · 9667feed
      Tim Peters authored
      NEEDS DOC CHANGES
      A few more AttributeErrors turned into TypeErrors, but in test_contains
      this time.
      The full story for instance objects is pretty much unexplainable, because
      instance_contains() tries its own flavor of iteration-based containment
      testing first, and PySequence_Contains doesn't get a chance at it unless
      instance_contains() blows up.  A consequence is that
          some_complex_number in some_instance
      dies with a TypeError unless some_instance.__class__ defines __iter__ but
      does not define __getitem__.
      9667feed
    • Tim Peters's avatar
      Make unicode.join() work nice with iterators. This also required a change · dff6b664
      Tim Peters authored
      to string.join(), so that when the latter figures out in midstream that
      it really needs unicode.join() instead, unicode.join() can actually get
      all the sequence elements (i.e., there's no guarantee that the sequence
      passed to string.join() can be iterated over *again* by unicode.join(),
      so string.join() must not pass on the original sequence object anymore).
      dff6b664
    • Tim Peters's avatar
      Mark string.join() as done. Turns out string_join() works "for free" now, · ff490887
      Tim Peters authored
      because PySequence_Fast() started working for free as soon as
      PySequence_Tuple() learned how to work with iterators.  For some reason
      unicode.join() still doesn't work, though.
      ff490887
    • Tim Peters's avatar
      Fix a tiny and unlikely memory leak. Was there before too, and actually · b1d9be73
      Tim Peters authored
      several of these turned up and got fixed during the iteration crusade.
      b1d9be73
    • Tim Peters's avatar
      Generalize tuple() to work nicely with iterators. · c6ebbea8
      Tim Peters authored
      NEEDS DOC CHANGES.
      This one surprised me!  While I expected tuple() to be a no-brainer, turns
      out it's actually dripping with consequences:
      1. It will *allow* the popular PySequence_Fast() to work with any iterable
         object (code for that not yet checked in, but should be trivial).
      2. It caused two std tests to fail.  This because some places used
         PyTuple_Sequence() (the C spelling of tuple()) as an indirect way to test
         whether something *is* a sequence.  But tuple() code only looked for the
         existence of sq->item to determine that, and e.g. an instance passed
         that test whether or not it supported the other operations tuple()
         needed (e.g., __len__).  So some things the tests *expected* to fail
         with an AttributeError now fail with a TypeError instead.  This looks
         like an improvement to me; e.g., test_coercion used to produce 559
         TypeErrors and 2 AttributeErrors, and now they're all TypeErrors.  The
         error details are more informative too, because the places calling this
         were *looking* for TypeErrors in order to replace the generic tuple()
         "not a sequence" msg with their own more specific text, and
         AttributeErrors snuck by that.
      c6ebbea8
    • Tim Peters's avatar
      Make PyIter_Next() a little smarter (wrt its knowledge of iterator · fe975c3b
      Tim Peters authored
      internals) so clients can be a lot dumber (wrt their knowledge).
      fe975c3b
  2. 04 May, 2001 4 commits
  3. 03 May, 2001 13 commits
  4. 02 May, 2001 12 commits
  5. 01 May, 2001 4 commits
    • Guido van Rossum's avatar
      Add more news about iterators. · e11da5f0
      Guido van Rossum authored
      e11da5f0
    • Tim Peters's avatar
      Generalize list(seq) to work with iterators. This also generalizes list() · 0771cb97
      Tim Peters authored
      to no longer insist that len(seq) be defined.
      NEEDS DOC CHANGES.
      This is meant to be a model for how other functions of this ilk (max,
      filter, etc) can be generalized similarly.  Feel encouraged to grab your
      favorite and convert it!
      Note some cute consequences:
          list(file) == file.readlines() == list(file.xreadlines())
          list(dict) == dict.keys()
          list(dict.iteritems()) = dict.items()
          list(xrange(i, j, k)) == range(i, j, k)
      0771cb97
    • Guido van Rossum's avatar
      5fe519ae
    • Guido van Rossum's avatar
      Printing objects to a real file still wasn't done right: if the · 25ab67b2
      Guido van Rossum authored
      object's type didn't define tp_print, there were still cases where the
      full "print uses str() which falls back to repr()" semantics weren't
      honored.  This resulted in
      
          >>> print None
          <None object at 0x80bd674>
          >>> print type(u'')
          <type object at 0x80c0a80>
      
      Fixed this by always using the appropriate PyObject_Repr() or
      PyObject_Str() call, rather than trying to emulate what they would do.
      
      Also simplified PyObject_Str() to always fall back on PyObject_Repr()
      when tp_str is not defined (rather than making an extra check for
      instances with a __str__ method).  And got rid of the special case for
      strings.
      25ab67b2