[Python-checkins] CVS: python/dist/src/Lib/test/output test_coercion,1.3,1.4

Tim Peters tim_one@users.sourceforge.net
2001年5月04日 20:56:39 -0700


Update of /cvsroot/python/python/dist/src/Lib/test/output
In directory usw-pr-cvs1:/tmp/cvs-serv17966/python/dist/src/Lib/test/output
Modified Files:
	test_coercion 
Log Message:
Generalize tuple() to work nicely with iterators.
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.
Index: test_coercion
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/output/test_coercion,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** test_coercion	2001年01月04日 01:36:25	1.3
--- test_coercion	2001年05月05日 03:56:37	1.4
***************
*** 517,521 ****
 [1] %= None ... exceptions.TypeError
 [1] + <MethodNumber 1> ... exceptions.TypeError
! [1] += <MethodNumber 1> ... exceptions.AttributeError
 [1] - <MethodNumber 1> ... exceptions.TypeError
 [1] -= <MethodNumber 1> ... exceptions.TypeError
--- 517,521 ----
 [1] %= None ... exceptions.TypeError
 [1] + <MethodNumber 1> ... exceptions.TypeError
! [1] += <MethodNumber 1> ... exceptions.TypeError
 [1] - <MethodNumber 1> ... exceptions.TypeError
 [1] -= <MethodNumber 1> ... exceptions.TypeError
***************
*** 529,533 ****
 [1] %= <MethodNumber 1> ... exceptions.TypeError
 [1] + <CoerceNumber 2> ... exceptions.TypeError
! [1] += <CoerceNumber 2> ... exceptions.AttributeError
 [1] - <CoerceNumber 2> ... exceptions.TypeError
 [1] -= <CoerceNumber 2> ... exceptions.TypeError
--- 529,533 ----
 [1] %= <MethodNumber 1> ... exceptions.TypeError
 [1] + <CoerceNumber 2> ... exceptions.TypeError
! [1] += <CoerceNumber 2> ... exceptions.TypeError
 [1] - <CoerceNumber 2> ... exceptions.TypeError
 [1] -= <CoerceNumber 2> ... exceptions.TypeError

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