You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When compiling a regular expression with groups (subpatterns),
circular references are created.
Here is an example to illustrate the problem:
>>> import gc
>>> import re
>>> gc.disable() # disable garbage collector
>>> gc.collect() # make sure we start with 0
0
>>> re.compile('(a|b)') # compile something with groups
re.compile('(a|b)')
>>> gc.collect() # collects x objects depending on the compiled string
11
Indeed, there is a regression, and your patch fixes it. But I don't like the idea of using weakref. For now sre_parse has very little dependencies, but weakref depends on collections that depends on a number of modules. For now importing weakref works, but it is too easy to create a dependency loop in future.
Here is alternative patch that gets rid of references at all. The subpatterns list was added in the patch for bpo-9179 and is an implementation detail. We can replace it with a list of subpattern widths.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: