[Python-Dev] Bug #113254: pre/sre difference breaks pyclbr

Guido van Rossum guido@beopen.com
Sat, 02 Sep 2000 12:18:48 -0500


> paul prescod spotted this discrepancy:
> 
> from the documentation:
> 
>     start ([group]) 
>     end ([group]) 
>         Return the indices of the start and end of the
>         substring matched by group; group defaults to
>         zero (meaning the whole matched substring). Return
>         None if group exists but did not contribute to the
>         match.
> 
> however, it turns out that PCRE doesn't do what it's
> supposed to:
> 
> >>> import pre
> >>> m = pre.match("(a)|(b)", "b")
> >>> m.start(1)
> -1
> 
> unlike SRE:
> 
> >>> import sre
> >>> m = sre.match("(a)|(b)", "b")
> >>> m.start(1)
> >>> print m.start(1)
> None
> 
> this difference breaks 1.6's pyclbr (1.5.2's pyclbr works
> just fine with SRE, though...)
> 
> :::
> 
> should I fix SRE and ask Fred to fix the docs, or should
> someone fix pyclbr and maybe even PCRE?

I'd suggest fix SRE and the docs, because -1 is a more useful
indicator for "no match" than None: it has the same type as valid
indices.  It makes it easier to adapt to static typing later.

--Guido van Rossum (home page: http://www.pythonlabs.com/~guido/)