Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle constants deprecated in Python 3.8 #420

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
nforro marked this conversation as resolved.
Show resolved Hide resolved
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
Loading