| 1 |
From: Thomas Goirand <[email protected]> |
| 2 |
Date: Wed, 1 Apr 2020 14:08:47 +0200 |
| 3 |
Subject: Python 3.9: fix collections import |
| 4 |
|
| 5 |
Bug-Debian: https://bugs.debian.org/949018 |
| 6 |
Forwarded: no |
| 7 |
Last-Update: 2020-02-27 |
| 8 |
|
| 9 |
As collections has moved to collections.abc, this produces a warning which |
| 10 |
may lead to unit testing errors: this is the case when building Rally. |
| 11 |
|
| 12 |
This patch attempts to import from collections.abc, and if it fails, falls |
| 13 |
back to collections. This should be harmless. |
| 14 |
|
| 15 |
Note that this patch is probably useless with future version, as hopefully, |
| 16 |
upstream will fix it (I didn't check). However, I didn't dare upgrading the |
| 17 |
package to the major upstream release 3.x. |
| 18 |
--- |
| 19 |
src/jinja2/lexer.py | 5 ++++- |
| 20 |
src/jinja2/nodes.py | 5 ++++- |
| 21 |
src/jinja2/sandbox.py | 5 ++++- |
| 22 |
src/jinja2/utils.py | 5 ++++- |
| 23 |
tests/test_utils.py | 5 ++++- |
| 24 |
5 files changed, 20 insertions(+), 5 deletions(-) |
| 25 |
|
| 26 |
--- a/src/jinja2/lexer.py |
| 27 |
+++ b/src/jinja2/lexer.py |
| 28 |
@@ -7,7 +7,10 @@ template code and python code in express |
| 29 |
import re |
| 30 |
import typing as t |
| 31 |
from ast import literal_eval |
| 32 |
-from collections import deque |
| 33 |
+try: |
| 34 |
+ from collections.abc import deque |
| 35 |
+except ImportError: |
| 36 |
+ from collections import deque |
| 37 |
from sys import intern |
| 38 |
|
| 39 |
from ._identifier import pattern as name_re |
| 40 |
--- a/src/jinja2/nodes.py |
| 41 |
+++ b/src/jinja2/nodes.py |
| 42 |
@@ -6,7 +6,10 @@ to normalize nodes. |
| 43 |
import inspect |
| 44 |
import operator |
| 45 |
import typing as t |
| 46 |
-from collections import deque |
| 47 |
+try: |
| 48 |
+ from collections.abc import deque |
| 49 |
+except ImportError: |
| 50 |
+ from collections import deque |
| 51 |
|
| 52 |
from markupsafe import Markup |
| 53 |
|
| 54 |
--- a/src/jinja2/sandbox.py |
| 55 |
+++ b/src/jinja2/sandbox.py |
| 56 |
@@ -7,7 +7,10 @@ import types |
| 57 |
import typing as t |
| 58 |
from _string import formatter_field_name_split # type: ignore |
| 59 |
from collections import abc |
| 60 |
-from collections import deque |
| 61 |
+try: |
| 62 |
+ from collections.abc import deque |
| 63 |
+except ImportError: |
| 64 |
+ from collections import deque |
| 65 |
from functools import update_wrapper |
| 66 |
from string import Formatter |
| 67 |
|
| 68 |
--- a/src/jinja2/utils.py |
| 69 |
+++ b/src/jinja2/utils.py |
| 70 |
@@ -4,7 +4,10 @@ import os |
| 71 |
import re |
| 72 |
import typing as t |
| 73 |
from collections import abc |
| 74 |
-from collections import deque |
| 75 |
+try: |
| 76 |
+ from collections.abc import deque |
| 77 |
+except ImportError: |
| 78 |
+ from collections import deque |
| 79 |
from random import choice |
| 80 |
from random import randrange |
| 81 |
from threading import Lock |
| 82 |
--- a/tests/test_utils.py |
| 83 |
+++ b/tests/test_utils.py |
| 84 |
@@ -1,7 +1,10 @@ |
| 85 |
import copy |
| 86 |
import pickle |
| 87 |
import random |
| 88 |
-from collections import deque |
| 89 |
+try: |
| 90 |
+ from collections.abc import deque |
| 91 |
+except ImportError: |
| 92 |
+ from collections import deque |
| 93 |
from copy import copy as shallow_copy |
| 94 |
|
| 95 |
import pytest |