From 89645cfd19d1480d586af50842f0ac264a036fa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Sun, 9 Jun 2024 21:45:31 +0200 Subject: [PATCH] Explicitly remove the ctx attribute in copy_ast_without_context Python 3.13.0b2+ defaults to Load when we don't pass ctx See https://github.com/python/cpython/pull/118871 --- pure_eval/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pure_eval/utils.py b/pure_eval/utils.py index a8a3730..19ead65 100644 --- a/pure_eval/utils.py +++ b/pure_eval/utils.py @@ -184,7 +184,12 @@ def copy_ast_without_context(x): if field != 'ctx' if hasattr(x, field) } - return type(x)(**kwargs) + a = type(x)(**kwargs) + if hasattr(a, 'ctx'): + # Python 3.13.0b2+ defaults to Load when we don't pass ctx + # https://github.com/python/cpython/pull/118871 + del a.ctx + return a elif isinstance(x, list): return list(map(copy_ast_without_context, x)) else: