Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2069)

#13592: repr(regex) doesn't include actual regex

Can't Edit
Can't Publish+Mail
Start Review
Created:
10 months, 1 week ago by spamfaenger
Modified:
2 months, 1 week ago
Reviewers:
ezio.melotti, thomas
CC:
rhettinger, terry.reedy, AntoinePitrou, ezio.melotti, mrabarnett, alex, cjerdonek, eric.snow, spamfaenger_gmx.de, hltbra
Visibility:
Public.

Patch Set 1 #

Total comments: 3

Patch Set 2 #

Patch Set 3 #

Total comments: 9
Unified diffs Side-by-side diffs Delta from patch set Stats Patch
Lib/sre_constants.py View 1 2 1 chunk +2 lines, -0 lines 0 comments Download
Lib/test/test_re.py View 1 2 1 chunk +38 lines, -0 lines 1 comment Download
Modules/_sre.c View 1 2 3 chunks +107 lines, -1 line 8 comments Download
Modules/sre_constants.h View 1 2 1 chunk +2 lines, -0 lines 0 comments Download

Messages

Total messages: 2
ezio.melotti
http://bugs.python.org/review/13592/diff/5455/Lib/test/test_re.py File Lib/test/test_re.py (right): http://bugs.python.org/review/13592/diff/5455/Lib/test/test_re.py#newcode928 Lib/test/test_re.py:928: self.assertEquals('re.compile("random pattern", re.UNICODE)', repr(pattern)) 3 comments: 1) assertEquals is ...
10 months, 1 week ago #1
twouters
2 months, 1 week ago #2
http://bugs.python.org/review/13592/diff/5467/Lib/test/test_re.py
File Lib/test/test_re.py (right):

http://bugs.python.org/review/13592/diff/5467/Lib/test/test_re.py#newcode958
Lib/test/test_re.py:958: def test_repr_with_single_quotes_inside(self):
For good measure, add a test with both types of quotes.

http://bugs.python.org/review/13592/diff/5467/Modules/_sre.c
File Modules/_sre.c (right):

http://bugs.python.org/review/13592/diff/5467/Modules/_sre.c#newcode2603
Modules/_sre.c:2603: pattern_repr(PatternObject *pattern);
If you move the definition up (for example, alongside pattern_dealloc) you won't
need this forward declaration.

http://bugs.python.org/review/13592/diff/5467/Modules/_sre.c#newcode2647
Modules/_sre.c:2647: item = Py_BuildValue("U", string);
This should just use "s" instead of "U", in Python 3.

http://bugs.python.org/review/13592/diff/5467/Modules/_sre.c#newcode2663
Modules/_sre.c:2663: separator = Py_BuildValue("U", string);
This should also use "s".

http://bugs.python.org/review/13592/diff/5467/Modules/_sre.c#newcode2678
Modules/_sre.c:2678: PatternFlag flags[] = {
Make this a (static) global array instead of an auto var.

http://bugs.python.org/review/13592/diff/5467/Modules/_sre.c#newcode2692
Modules/_sre.c:2692: if (!list)
Compare against NULL explicitly, instead of using !list. "if (list == NULL)'.

http://bugs.python.org/review/13592/diff/5467/Modules/_sre.c#newcode2695
Modules/_sre.c:2695: return NULL;
This leaks the reference to 'list'. The usual pattern here is to assign NULL to
all objects you might to deallocate in error paths, do XDECREFs in a separate
error path and use 'goto error' to jump there.

The same goes for almost all return statements below.

http://bugs.python.org/review/13592/diff/5467/Modules/_sre.c#newcode2700
Modules/_sre.c:2700: return NULL;
for pattern_repr, since you DECREF it after this call and this is the only case
in which you need to handle it, you probably want to DECREF it and then goto
error.

http://bugs.python.org/review/13592/diff/5467/Modules/_sre.c#newcode2703
Modules/_sre.c:2703: flag_items = PyList_New(0);
Since you can look at the flags and see instantly whether you're going to need
this, you can turn the PyList_Size() check below into a 'if obj->flags' check
right here, and skip the rest of the code if there are no flags. For
maintainability it's probably a good idea to define a new SRE_FLAG_ALLFLAGS or
such that is the bitwise-or of all possible flags, and add it to sre_constants.h
(in case the sre module grows uses of the flags int that *isn't* an actual
flag.) You can then write the quick check for flags as 'if (obj->flags &
SRE_FLAG_ALLFLAGS)'.
Sign in to reply to this message.

RSS Feeds Recent Issues | This issue
This is Rietveld cbc36f91f3f7