Opened 9 years ago
Closed 9 years ago
#27549 closed Bug (needsinfo)
django.utils.functional.lazy cannot be used with regular expressions module (re)
| Reported by: | Daniel Hahler | Owned by: | nobody | 
|---|---|---|---|
| Component: | Utilities | Version: | dev | 
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no | 
| Needs tests: | no | Patch needs improvement: | no | 
| Easy pickings: | no | UI/UX: | no | 
Description
from django.utils.functional import lazy
import re
f = lazy(lambda: 's', str)()
re.match('s', f)
results in TypeError: expected string or bytes-like object.
This gets generated in https://github.com/python/cpython/blob/e02afa7a78f1515dd7386912812685fb4d519a44/Modules/_sre.c#L338-L342, where the PyObject_GetBuffer call appears to fail.
Change History (2)
comment:1 by , 9 years ago
comment:2 by , 9 years ago
| Resolution: | → needsinfo | 
|---|---|
| Status: | new → closed | 
Please reopen if anyone has an idea about an implementation or can provide a patch.
  Note:
 See   TracTickets
 for help on using tickets.
    
In general,
lazystuff in Django is safe for Django's own code, but not for any Python code. It's explained for example in https://docs.djangoproject.com/en/stable/topics/i18n/translation/#working-with-lazy-translation-objectsIf you think a fix is possible for this, why not, but I think you are not the first to try and I'm not sure it's possible.