Opened 8 years ago

Closed 8 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 Claude Paroz, 8 years ago

In general, lazy stuff 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-objects

If 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.

comment:2 by Tim Graham, 8 years ago

Resolution: needsinfo
Status: newclosed

Please reopen if anyone has an idea about an implementation or can provide a patch.

Note: See TracTickets for help on using tickets.
Back to Top