interegular icon indicating copy to clipboard operation
interegular copied to clipboard

add __bool__ for an FSM

Open KommuSoft opened this issue 1 year ago • 1 comments

Currently when using if my_fsm, it will fallback on __len__ which will raise an OverflowError in case there are an infinite many strings that match the FSM.

We can just check if the FSM is empty. This is "equivalent" with the current implementation in the sense that for FSMs that accept a finite number of strings, the bool will be the same for both versions, but by adding a __bool__ we will also return True if an infinite amount of strings are accepted, and it is less computationally expensive.

KommuSoft avatar Mar 06 '24 10:03 KommuSoft

Is the library doing if fsm somewhere? Otherwise, use greenery instead. For interegular FSM is really just an internal detail, and I want to move over to just using greenery.fsm.FSM at some point to reduce complexity of this package. Their implementation is also just better.

MegaIng avatar Mar 06 '24 11:03 MegaIng