Skip to content

Commit

Permalink
fixup! Rename (force|smart)_text to (force|smart)_str
Browse files Browse the repository at this point in the history
Also Import lru_cache from seddable place
  • Loading branch information
hmpf committed Oct 22, 2021
1 parent 26f72b1 commit 0eda8c5
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions python/nav/compatibility.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Django 4.0:
# s/nav.compatibility \(import force_str\)/django.utils.encoding \1/'
# Django 2.2 has only *_text, Django 3.2 has both *_text and *_str,
# Django 4.0 has only *_str. These are imported so many places that
# it is better to do it once, hence this file

# When no longer supporting 2.2:
# s/nav.compatibility \(import \w+_str\)/django.utils.encoding \1/
try:
from django.utils.encoding import force_str
except ImoprtError:
Expand All @@ -9,3 +13,13 @@
from django.utils.encoding import smart_str
except ImoprtError:
from django.utils.encoding import smart_text as smart_str

# lru_cache isn't used that much but one application of sed is faster
# than changing a block into a line three times.

# When no longer supporting 2.2:
# s/nav.compatibility import lru_cache/functools import lru_cache/
try:
from functools import lru_cache
except ImportError:
from django.utils.lru_cache import lru_cache

0 comments on commit 0eda8c5

Please sign in to comment.