Message359039
The problematic `findall(...)[0]` is a common anti-pattern in Python programs. The reason is lack of symmetry and completeness in the `re` module.
The original proposal in `python-ideas` was to add `re.findfirst(pattern, string, flags=0, default=_mark)` with more or less the semantics of `next(findall(pattern, string, flags=flags), default=default)`.
The referenced PR adds `findalliter(pattern, string, flags=0)` with the value semantics of `findall()` over a generator, implements `findall()` as `return list(findalliter(...))`, and implements `findfirst()`.
Consistency and correctness are likely because all tests pass with the redefined `findall()`. |
|
Date |
User |
Action |
Args |
2019-12-30 13:19:05 | apalala | set | recipients:
+ apalala |
2019-12-30 13:19:05 | apalala | set | messageid: <1577711945.6.0.0241743491206.issue39165@roundup.psfhosted.org> |
2019-12-30 13:19:05 | apalala | link | issue39165 messages |
2019-12-30 13:19:05 | apalala | create | |
|