[Python-ideas] Adding function checks to regex

Masklinn masklinn at masklinn.net
Sat Mar 19 22:32:14 CET 2011

On 2011-03-19, at 17:35 , Calvin Spealman wrote:

> I am -1 on the whole idea.
> However, for the sake of argument, I'll say that if it was done I would not
> bind the callbacks at match time.
> Instead, they would be part of the compiled regex objects.
> r = re.compile(r"foo:(?C<check_bounds>\d+)", check_bounds=lambda d: 1 <=
> int(d) <= 100)
> and then r could be used like any other regex, and you don't need to know
> about the callbacks when actually using it, just to build it.
That's equivalent to Peter's code though: you're compiling a regex object, he was using one of the module-level functions.

That's similar to the way `flags` are used: they're provided to the module-level function (including compile), but not to the SRE_Pattern methods.

More information about the Python-ideas mailing list