From 93bc53cbf15c078cb585345ce60a1bbc8fd15813 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Thu, 17 Oct 2024 17:26:30 +0200 Subject: [PATCH] Handle constants deprecated in Python 3.8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nikola Forró --- specfile/formatter.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/specfile/formatter.py b/specfile/formatter.py index 6dd8811..bde0a60 100644 --- a/specfile/formatter.py +++ b/specfile/formatter.py @@ -3,6 +3,7 @@ import ast import functools +import sys from typing import Callable from specfile.exceptions import SpecfileException @@ -29,12 +30,14 @@ def format_expression(expression: str, line_length_threshold: int = 80) -> str: def fmt(node, indent=0, prefix="", multiline=False): result = " " * indent + prefix - if isinstance(node, (ast.Constant, ast.NameConstant)): + if sys.version_info < (3, 8) and isinstance(node, ast.NameConstant): result += repr(node.value) - elif isinstance(node, ast.Str): + elif sys.version_info < (3, 8) and isinstance(node, ast.Str): result += repr(node.s) - elif isinstance(node, ast.Num): + elif sys.version_info < (3, 8) and isinstance(node, ast.Num): result += repr(node.n) + elif isinstance(node, ast.Constant): + result += repr(node.value) elif isinstance(node, (ast.Tuple, ast.List, ast.Dict, ast.Call)): if isinstance(node, ast.Tuple): start, end = "(", ")" if multiline or len(node.elts) != 1 else ",)"