classification
Title: better message for re.search TypeError ("expected string or bytes-like object")
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Ido Michael, chris.jerdonek, zihengcat
Priority: normal Keywords:

Created on 2020-05-22 21:12 by chris.jerdonek, last changed 2020-05-26 06:07 by zihengcat.

Messages (4)
msg369652 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2020-05-22 21:12
This TypeError could be a bit better:

"/Users/runner/runners/2.262.1/work/cpython/cpython/Lib/test/test_nntplib.py", line 293, in test_with_statement
    if re.search(r'(?i)KEY.TOO.SMALL', ssl_err.reason):
  File "/Users/runner/runners/2.262.1/work/cpython/cpython/Lib/re.py", line 201, in search
    return _compile(pattern, flags).search(string)
TypeError: expected string or bytes-like object

It just says "expected string or bytes-like object" but could include what type it found.
msg369884 - (view) Author: Ido Michael (Ido Michael) * Date: 2020-05-25 14:58
I agree it should be more informative and have the same standard as the rest of the Errors messages.

Can I start a PR?
msg369926 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2020-05-25 21:51
I already started one actually. But if I don't get to it in a week, I'll make a note here and you can take it up.
msg369945 - (view) Author: zihengCat (zihengcat) * Date: 2020-05-26 06:07
Does it mean modify `cpython/Modules/_sre.c` and add `PyObject` information to PyError string ?

https://github.com/python/cpython/blob/master/Modules/_sre.c#L376
History
Date User Action Args
2020-05-26 06:07:30zihengcatsetnosy: + zihengcat
messages: + msg369945
2020-05-25 21:51:17chris.jerdoneksetmessages: + msg369926
2020-05-25 14:58:04Ido Michaelsetnosy: + Ido Michael
messages: + msg369884
2020-05-22 21:12:55chris.jerdonekcreate