Skip to content

Commit

Permalink
Remove unnecessary sys.version_info checks from tests
Browse files Browse the repository at this point in the history
Our minimum supported Python version 3.9 and these things were added
way before it was releases, so there is no need to keep them.
  • Loading branch information
berkerpeksag committed Jan 2, 2025
1 parent 5cd679f commit 49a5de4
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 40 deletions.
4 changes: 1 addition & 3 deletions astor/code_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,6 @@ def _handle_string_constant(self, node, value, is_joined=False):
current_line[0] = current_line[0][str_index:]
current_line = ''.join(current_line)

has_ast_constant = sys.version_info >= (3, 6)

if is_joined:
# Handle new f-strings. This is a bit complicated, because
# the tree can contain subnodes that recurse back to JoinedStr
Expand All @@ -708,7 +706,7 @@ def recurse(node):
if value.format_spec is not None:
self.write(':')
recurse(value.format_spec)
elif has_ast_constant and isinstance(value, ast.Constant):
elif isinstance(value, ast.Constant):
self.write(value.value)
else:
kind = type(value).__name__
Expand Down
12 changes: 3 additions & 9 deletions astor/rtrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@

dsttree = 'tmp_rtrip'

# TODO: Remove this workaround once we remove version 2 support


def out_prep(s, pre_encoded=(sys.version_info[0] == 2)):
return s if pre_encoded else s.encode('utf-8')


def convert(srctree, dsttree=dsttree, readonly=False, dumpall=False,
ignore_exceptions=False, fullcomp=False):
Expand Down Expand Up @@ -90,7 +84,7 @@ def convert(srctree, dsttree=dsttree, readonly=False, dumpall=False,
dstfname = os.path.join(dstpath, fname)
try:
with open(dstfname, 'wb') as f:
f.write(out_prep(dsttxt))
f.write(dsttxt.encode('utf-8'))
except UnicodeEncodeError:
badfiles.add(dstfname)

Expand All @@ -117,12 +111,12 @@ def convert(srctree, dsttree=dsttree, readonly=False, dumpall=False,
if not readonly:
try:
with open(dstfname[:-3] + '.srcdmp', 'wb') as f:
f.write(out_prep(srcdump))
f.write(srcdump.encode('utf-8'))
except UnicodeEncodeError:
badfiles.add(dstfname[:-3] + '.srcdmp')
try:
with open(dstfname[:-3] + '.dstdmp', 'wb') as f:
f.write(out_prep(dstdump))
f.write(dstdump.encode('utf-8'))
except UnicodeEncodeError:
badfiles.add(dstfname[:-3] + '.dstdmp')
elif dumpall:
Expand Down
27 changes: 1 addition & 26 deletions tests/test_code_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ def test(a1, a2, b1=j, b2='123', b3={}, b4=[]):
pass"""
self.assertSrcRoundtrips(source)

@unittest.skipUnless(sys.version_info >= (3, 8, 0, "alpha", 4),
"positional only arguments introduced in Python 3.8")
def test_positional_only_arguments(self):
source = """
def test(a, b, /, c, *, d, **kwargs):
Expand Down Expand Up @@ -518,23 +516,6 @@ def test_assignment_expr(self):
for case in cases:
self.assertAstRoundtripsGtVer(case, (3, 8))

@unittest.skipUnless(sys.version_info <= (3, 3),
"ast.Name used for True, False, None until Python 3.4")
def test_deprecated_constants_as_name(self):
self.assertAstEqualsSource(
ast.Assign(targets=[ast.Name(id='spam')], value=ast.Name(id='True')),
"spam = True")

self.assertAstEqualsSource(
ast.Assign(targets=[ast.Name(id='spam')], value=ast.Name(id='False')),
"spam = False")

self.assertAstEqualsSource(
ast.Assign(targets=[ast.Name(id='spam')], value=ast.Name(id='None')),
"spam = None")

@unittest.skipUnless(sys.version_info >= (3, 4),
"ast.NameConstant introduced in Python 3.4")
def test_deprecated_name_constants(self):
self.assertAstEqualsSource(
ast.Assign(targets=[ast.Name(id='spam')], value=ast.NameConstant(value=True)),
Expand Down Expand Up @@ -575,8 +556,6 @@ def test_deprecated_constant_nodes(self):
ast.Assign(targets=[ast.Name(id='spam')], value=ast.Str("String")),
"spam = 'String'")

@unittest.skipUnless(sys.version_info >= (3, 6),
"ast.Constant introduced in Python 3.6")
def test_constant_nodes(self):
self.assertAstEqualsSource(
ast.Assign(targets=[ast.Name(id='spam')], value=ast.Constant(value=3)),
Expand Down Expand Up @@ -634,9 +613,6 @@ def test_annassign(self):
"""
self.assertAstRoundtripsGtVer(source, (3, 6))

@unittest.skipUnless(sys.version_info >= (3, 6),
"typing and annotated assignment was introduced in "
"Python 3.6")
def test_function_typing(self):
source = canonical("""
def foo(x : int) ->str:
Expand All @@ -649,6 +625,7 @@ def foo(x: int) -> str:
return i
""")
self.assertAstEqualsSource(ast.parse(source), target)
self.assertAstRoundtripsGtVer(source, (3, 6))

def test_compile_types(self):
code = '(a + b + c) * (d + e + f)\n'
Expand Down Expand Up @@ -996,8 +973,6 @@ def test_fstring_escaped_braces(self):
'''
self.assertSrcRoundtripsGtVer(source, (3, 6))

@unittest.skipUnless(sys.version_info >= (3, 8, 0, "alpha", 4),
"f-string debugging introduced in Python 3.8")
def test_fstring_debugging(self):
source = """
x = f'{5=}'
Expand Down
2 changes: 0 additions & 2 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

class GetSymbolTestCase(unittest.TestCase):

@unittest.skipUnless(sys.version_info >= (3, 5),
"ast.MatMult introduced in Python 3.5")
def test_get_mat_mult(self):
self.assertEqual('@', astor.get_op_symbol(ast.MatMult()))

Expand Down

0 comments on commit 49a5de4

Please sign in to comment.