Skip to content

Commit

Permalink
Handle constants deprecated in Python 3.8 (#420)
Browse files Browse the repository at this point in the history
Handle constants deprecated in Python 3.8

Fixes #419.

Reviewed-by: Matej Focko
Reviewed-by: Nikola Forró
  • Loading branch information
softwarefactory-project-zuul[bot] authored Oct 17, 2024
2 parents 4ab4336 + 93bc53c commit ee026ad
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions specfile/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import ast
import functools
import sys
from typing import Callable

from specfile.exceptions import SpecfileException
Expand All @@ -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 ",)"
Expand Down

0 comments on commit ee026ad

Please sign in to comment.