Proposal: Expose FilteredRE2 atoms in Python bindings

5 views
Skip to first unread message

Akshay Joshi

unread,
Dec 15, 2025, 9:32:53 PM (3 days ago) Dec 15
to re2...@googlegroups.com
Hi there,

I'd like to propose a small change to the Python bindings: making `Filter.Compile()` return the extracted literal atoms instead of `None`.

The C++ `FilteredRE2::Compile()` currently extracts atoms that must appear for any pattern to match. These are useful for building secondary indexes (bloom filters, n-gram indexes) to prefilter candidates before running expensive regex matches.

Currently, the Python `Filter` class computes these atoms internally but doesn't expose them. The Python wrapper then discards the bool value and implicitly returns None.

The current return value is always None, so `if f.Compile():` is always false. Returning a list would make this truthy when atoms are extracted, which would arguably be more useful than the current return value. The only breaking case would be explicit `if result is None:` checks, which seems unlikely given the undocumented None return.

Questions:

1. Is this the right approach, or would a separate `GetAtoms()` method be preferred?
2. Any concerns about storing atoms as a member variable?

Happy to send a PR if this sounds reasonable.

Thanks,

Akshay
Reply all
Reply to author
Forward
0 new messages