Skip to content

Commit

Permalink
Merge pull request #3278 from wisp3rwind/fix-ast-py38
Browse files Browse the repository at this point in the history
functemplate: Adapt ast syntax to PEP570 changes on python3.8
  • Loading branch information
sampsyo committed May 30, 2019
2 parents 0ad084a + ade1df5 commit 7499130
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions beets/util/functemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,29 +118,30 @@ def compile_func(arg_names, statements, name='_the_func', debug=False):
bytecode of the compiled function.
"""
if six.PY2:
func_def = ast.FunctionDef(
name=name.encode('utf-8'),
args=ast.arguments(
args=[ast.Name(n, ast.Param()) for n in arg_names],
vararg=None,
kwarg=None,
defaults=[ex_literal(None) for _ in arg_names],
),
body=statements,
decorator_list=[],
name = name.encode('utf-8')
args = ast.arguments(
args=[ast.Name(n, ast.Param()) for n in arg_names],
vararg=None,
kwarg=None,
defaults=[ex_literal(None) for _ in arg_names],
)
else:
func_def = ast.FunctionDef(
name=name,
args=ast.arguments(
args=[ast.arg(arg=n, annotation=None) for n in arg_names],
kwonlyargs=[],
kw_defaults=[],
defaults=[ex_literal(None) for _ in arg_names],
),
body=statements,
decorator_list=[],
)
args_fields = {
'args': [ast.arg(arg=n, annotation=None) for n in arg_names],
'kwonlyargs': [],
'kw_defaults': [],
'defaults': [ex_literal(None) for _ in arg_names],
}
if 'posonlyargs' in ast.arguments._fields: # Added in Python 3.8.
args_fields['posonlyargs'] = []
args = ast.arguments(**args_fields)

func_def = ast.FunctionDef(
name=name,
args=args,
body=statements,
decorator_list=[],
)

# The ast.Module signature changed in 3.8 to accept a list of types to
# ignore.
Expand Down

0 comments on commit 7499130

Please sign in to comment.