a8f3eea
From dab0c1f9abda5b17cc7488f89a6fe08be7bc56a0 Mon Sep 17 00:00:00 2001
a8f3eea
From: wisp3rwind <17089248+wisp3rwind@users.noreply.github.com>
a8f3eea
Date: Tue, 9 Jun 2020 19:34:31 +0200
a8f3eea
Subject: [PATCH] compatibility with breaking changes to the ast module
a8f3eea
a8f3eea
new in 3.10, also backported to 3.8 and 3.9: https://github.com/python/cpython/pull/20649
a8f3eea
In fact, our generation of some Literals has been invalid since Python
a8f3eea
3.4, fix that too.
a8f3eea
---
a8f3eea
 beets/util/functemplate.py | 29 ++++++++++++++++++++---------
a8f3eea
 docs/changelog.rst         |  1 +
a8f3eea
 2 files changed, 21 insertions(+), 9 deletions(-)
a8f3eea
a8f3eea
diff --git a/beets/util/functemplate.py b/beets/util/functemplate.py
a8f3eea
index af22b790822b..266534a9b465 100644
a8f3eea
--- a/beets/util/functemplate.py
a8f3eea
+++ b/beets/util/functemplate.py
a8f3eea
@@ -73,15 +73,26 @@ def ex_literal(val):
a8f3eea
     """An int, float, long, bool, string, or None literal with the given
a8f3eea
     value.
a8f3eea
     """
a8f3eea
-    if val is None:
a8f3eea
-        return ast.Name('None', ast.Load())
a8f3eea
-    elif isinstance(val, six.integer_types):
a8f3eea
-        return ast.Num(val)
a8f3eea
-    elif isinstance(val, bool):
a8f3eea
-        return ast.Name(bytes(val), ast.Load())
a8f3eea
-    elif isinstance(val, six.string_types):
a8f3eea
-        return ast.Str(val)
a8f3eea
-    raise TypeError(u'no literal for {0}'.format(type(val)))
a8f3eea
+    if sys.version_info[:2] < (3, 4):
a8f3eea
+        if val is None:
a8f3eea
+            return ast.Name('None', ast.Load())
a8f3eea
+        elif isinstance(val, six.integer_types):
a8f3eea
+            return ast.Num(val)
a8f3eea
+        elif isinstance(val, bool):
a8f3eea
+            return ast.Name(bytes(val), ast.Load())
a8f3eea
+        elif isinstance(val, six.string_types):
a8f3eea
+            return ast.Str(val)
a8f3eea
+        raise TypeError(u'no literal for {0}'.format(type(val)))
a8f3eea
+    elif sys.version_info[:2] < (3, 6):
a8f3eea
+        if val in [None, True, False]:
a8f3eea
+            return ast.NameConstant(val)
a8f3eea
+        elif isinstance(val, six.integer_types):
a8f3eea
+            return ast.Num(val)
a8f3eea
+        elif isinstance(val, six.string_types):
a8f3eea
+            return ast.Str(val)
a8f3eea
+        raise TypeError(u'no literal for {0}'.format(type(val)))
a8f3eea
+    else:
a8f3eea
+        return ast.Constant(val)
a8f3eea
 
a8f3eea
 
a8f3eea
 def ex_varassign(name, expr):
a8f3eea
-- 
a8f3eea
2.26.2
a8f3eea