It's a little similar to the reasoning behind PEP 618 (adding the `strict` argument to `zip`).
A keyword argument is easier to add, and makes the code less ugly, then an `if` clause. When I don't have that `if` clause you mentioned in my code, it's not because I forgot, it's because I don't want an extra clause for something I don't think is going to happen. Also, a keyword argument enables code linters to enforce a rule that the `require` argument must always be specified. (Example <https://docs.astral.sh/ruff/rules/zip-without-explicit-strict/>.) On Sat, Oct 21, 2023 at 1:45 PM Paul Moore <p.f.mo...@gmail.com> wrote: > I don't see how it's more likely that people would remember to add a > `require=True` flag than to add `if m: raise RuntimeError("No match")`. The > problem here is people forgetting that a match can fail, not lack of a > means to handle that problem. > > Paul > > On Sat, 21 Oct 2023 at 11:38, Ram Rachum <r...@rachum.com> wrote: > >> Hey, >> >> I bet this has been discussed before but I couldn't find it. I'd >> appreciate it if anyone could point me to that thread. >> >> I'm sick of seeing "AttributeError: 'NoneType' object has no attribute >> 'foo'" whenever there's a `re.match` operation that fails while the code >> expects it to succeed. What do you think about a flag `require` such that >> `re.match(pattern, string, require=True)` would either return a match or >> raise an exception with an actually useful message? >> >> >> Thanks, >> Ram. >> _______________________________________________ >> Python-ideas mailing list -- python-ideas@python.org >> To unsubscribe send an email to python-ideas-le...@python.org >> https://mail.python.org/mailman3/lists/python-ideas.python.org/ >> Message archived at >> https://mail.python.org/archives/list/python-ideas@python.org/message/PLF46RTMGJUIXRPXPLHZUPLTLGE47TQA/ >> Code of Conduct: http://python.org/psf/codeofconduct/ >> >
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/3MPSWTKM6TS6NC3OWQUSCU237IZLXLYE/ Code of Conduct: http://python.org/psf/codeofconduct/