From 7f0b34f20583c34e8556398060df282a270b16a1 Mon Sep 17 00:00:00 2001 From: mementorc Date: Sun, 5 Apr 2026 12:06:44 -0500 Subject: [PATCH] fix: Support Python 3.14 where ast._Unparser was moved Python 3.14 moved ast._Unparser to _ast_unparse.Unparser (C extension module). Add conditional import to support both 3.10-3.13 (ast._Unparser) and 3.14+ (_ast_unparse.Unparser). All internal APIs (visit, traverse, fill, write, _indent, _source) remain identical in the new location. Fixes #91 --- refactor/ast.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/refactor/ast.py b/refactor/ast.py index 3d23262..be90edb 100644 --- a/refactor/ast.py +++ b/refactor/ast.py @@ -107,7 +107,14 @@ def unparse(self, node: ast.AST) -> str: ... # pragma: no cover -class BaseUnparser(ast._Unparser): # type: ignore +try: + _UnparserBase = ast._Unparser +except AttributeError: + # Python 3.14+: _Unparser moved to C extension module + from _ast_unparse import Unparser as _UnparserBase # type: ignore[import-not-found] + + +class BaseUnparser(_UnparserBase): # type: ignore """A public :py:class:`ast._Unparser` API that can be used to customize the AST re-synthesis process."""