New submission from ProFatXuanAll <profatxuan...@gmail.com>:

When I run the following code, I expected to get output result `['i am next 
line with [unk]']`, but instead I get the original list in `data`.

Code snippet

```py
import re

data = [
    '= hello =',
    'i am next line with <unk>',
]

pttn = re.compile(r'=.*=')
samples = filter(lambda sample: not pttn.match(sample), data)

pttn = re.compile(r'<unk>')
samples = map(lambda sample: pttn.sub('[unk]', sample), samples)

print(list(samples))
```

I suspect that is the cache provide by `re.compile` cause the problem.
The `sub` function in `map` is somehow begin link to the first `pttn`.

If I instead rename the second `pttn` to `pttn2`, then it work magically, but 
this is not expected.

----------
components: Regular Expressions
files: rebug.py
messages: 381907
nosy: ProFatXuanAll, ezio.melotti, mrabarnett
priority: normal
severity: normal
status: open
title: wrongly cache pattern by re.compile
type: behavior
versions: Python 3.8
Added file: https://bugs.python.org/file49625/rebug.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue42475>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to