Page MenuHomePhabricator

Match.group and Match.__getitem__(g) do not raise the same Exception
Closed, ResolvedPublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

import re
text = 'abcd'
pat = re.compile('z')
m = pat.search(text)

In [11]: m.group()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [11], in <cell line: 1>()
----> 1 m.group()

AttributeError: 'NoneType' object has no attribute 'group'

In [12]: m[0]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [12], in <cell line: 1>()
----> 1 m[0]

TypeError: 'NoneType' object is not subscriptable

What happens?:
Scripts might not catch the right Exception after https://gerrit.wikimedia.org/r/c/pywikibot/core/+/836138

Event Timeline

Change 837203 had a related patch set uploaded (by Mpaa; author: Mpaa):

[pywikibot/core@master] [bugfix]: Catch TypeError instead of AttributeError

https://gerrit.wikimedia.org/r/837203

A lot of files have been changed by https://gerrit.wikimedia.org/r/c/pywikibot/core/+/836138.
This might occur somewhere else.

Change 837203 merged by jenkins-bot:

[pywikibot/core@master] [bugfix]: Catch TypeError instead of AttributeError

https://gerrit.wikimedia.org/r/837203

Xqt assigned this task to Mpaa.

Didn't found any other problems or they were never handled.