Skip to content

Commit

Permalink
Merge pull request #3621 from wisp3rwind/fix_ast_39
Browse files Browse the repository at this point in the history
Compatibility with breaking changes to the ast module
  • Loading branch information
sampsyo committed Jun 10, 2020
2 parents 9b47e4f + dab0c1f commit 31855a9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
29 changes: 20 additions & 9 deletions beets/util/functemplate.py
Expand Up @@ -73,15 +73,26 @@ def ex_literal(val):
"""An int, float, long, bool, string, or None literal with the given
value.
"""
if val is None:
return ast.Name('None', ast.Load())
elif isinstance(val, six.integer_types):
return ast.Num(val)
elif isinstance(val, bool):
return ast.Name(bytes(val), ast.Load())
elif isinstance(val, six.string_types):
return ast.Str(val)
raise TypeError(u'no literal for {0}'.format(type(val)))
if sys.version_info[:2] < (3, 4):
if val is None:
return ast.Name('None', ast.Load())
elif isinstance(val, six.integer_types):
return ast.Num(val)
elif isinstance(val, bool):
return ast.Name(bytes(val), ast.Load())
elif isinstance(val, six.string_types):
return ast.Str(val)
raise TypeError(u'no literal for {0}'.format(type(val)))
elif sys.version_info[:2] < (3, 6):
if val in [None, True, False]:
return ast.NameConstant(val)
elif isinstance(val, six.integer_types):
return ast.Num(val)
elif isinstance(val, six.string_types):
return ast.Str(val)
raise TypeError(u'no literal for {0}'.format(type(val)))
else:
return ast.Constant(val)


def ex_varassign(name, expr):
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.rst
Expand Up @@ -213,6 +213,7 @@ Fixes:
* :doc:`/plugins/lyrics`: Fix crash when writing ReST files for a query without
results or fetched lyrics
:bug:`2805`
* Adapt to breaking changes in Python's ``ast`` module in 3.8

For plugin developers:

Expand Down

0 comments on commit 31855a9

Please sign in to comment.