This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author fgracia
Recipients ezio.melotti, fgracia, mrabarnett, rhettinger
Date 2012-05-27.20:40:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1338151203.19.0.06850733915.issue14924@psf.upfronthosting.co.za>
In-reply-to
Content
Thank you both for your quick and clear explanations. However I regret that I keep considering the situation rather unsatisfactory.

I can well understand that all objects are true and even that the convention that applies to some of them, like containers, that when they are empty they be considered false, does not apply to iterators; no doubt there will be good reasons for it being so. What seems illogical to me is that a method like *re.finditer()* returns as the result of its execution something that can only be interpreted as implying that what happened is exactly the contrary of what it really was. Why does it have to return anything different from the standard *None* when the match fails, like any other operation that fails? What use is in an *iterator* that leads nowhere?

I would find clarifying if at least the documentation formulated unambigously that it is unwise to submit iterators (and specifically the ones returned by methods like *finditer()* whose same names imply the opposite) to logical testing and that the only valid use they have is as arguments in *for* loops.

I think that the same vagorosity in this respect transpires in other places of the documentation. For instance in paragraph 7.2.5 of *re.html* it is said:

   Match objects always have a boolean value of *True*, so that you can test whether e. g. *match()* resulted in a match with a simple *if* statement.

As it is formulated, this clause is clearly contradictory: if something points always in the same direction, it cannot be used as the basis for any decission about which of two roads to take. Match objects can very well be always true (in fact, as all objects are in this sense, as paragraph 5.1 of *stdtypes.html* comes close to formulating it); what happens is that *re.match()* or *re.search()* do not return them when they fail, but the familiar and well behaved *None* value.
History
Date User Action Args
2012-05-27 20:40:03fgraciasetrecipients: + fgracia, rhettinger, ezio.melotti, mrabarnett
2012-05-27 20:40:03fgraciasetmessageid: <1338151203.19.0.06850733915.issue14924@psf.upfronthosting.co.za>
2012-05-27 20:40:02fgracialinkissue14924 messages
2012-05-27 20:40:02fgraciacreate