Skip to content

Parsing tests are failing with python 3.12.0-beta.1 #25185

@sylee957

Description

@sylee957

I see some issues with tests are failing in recent PRs after the python 3.12 beta is released
I attempt to fix some deprecation issues, #25184, however, I don't think that it fixes the test failing
and I'm unsure if some semantics are changed in the ast library or if it is some regression

=================================== FAILURES ===================================
________________________________ test_sympify1 _________________________________
sympy/core/sympify.py:495: in sympify
    expr = parse_expr(a, local_dict=locals, transformations=transformations, evaluate=evaluate)
sympy/parsing/sympy_parser.py:1072: in parse_expr
    code = stringify_expr(s, local_dict, global_dict, _transformations)
sympy/parsing/sympy_parser.py:891: in stringify_expr
    for toknum, tokval, _, _, _ in generate_tokens(input_code.readline):
/opt/hostedtoolcache/Python/3.12.0-beta.1/x64/lib/python3.12/tokenize.py:451: in _tokenize
    for token in _generate_tokens_from_c_tokenizer(source, extra_tokens=True):
/opt/hostedtoolcache/Python/3.12.0-beta.1/x64/lib/python3.12/tokenize.py:542: in _generate_tokens_from_c_tokenizer
    for info in c_tokenizer.TokenizerIter(source, extra_tokens=extra_tokens):
E     File "<string>", line 1
E       .[052631578947368421]
E         ^
E   SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers

During handling of the above exception, another exception occurred:
sympy/core/tests/test_sympify.py:61: in test_sympify1
    assert sympify('.[052631578947368421]') == Rational(1, 19)
sympy/core/sympify.py:497: in sympify
    raise SympifyError('could not parse %r' % a, exc)
E   sympy.core.sympify.SympifyError: Sympify of expression 'could not parse '.[052631578947368421]'' failed, because of exception being raised:
E   SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers (<string>, line 1)
____________________________ test_sympify_factorial ____________________________
ValueError: Error from parse_expr with transformed code: "Symbol ('x' )!\n"

The above exception was the direct cause of the following exception:
sympy/core/sympify.py:495: in sympify
    expr = parse_expr(a, local_dict=locals, transformations=transformations, evaluate=evaluate)
sympy/parsing/sympy_parser.py:1087: in parse_expr
    raise e from ValueError(f"Error from parse_expr with transformed code: {code!r}")
sympy/parsing/sympy_parser.py:1078: in parse_expr
    rv = eval_expr(code, local_dict, global_dict)
sympy/parsing/sympy_parser.py:906: in eval_expr
    expr = eval(
E     File "<string>", line 1
E       Symbol ('x' )!
E                    ^
E   SyntaxError: invalid syntax

During handling of the above exception, another exception occurred:
sympy/core/tests/test_sympify.py:237: in test_sympify_factorial
    assert sympify('x!') == factorial(x)
sympy/core/sympify.py:497: in sympify
    raise SympifyError('could not parse %r' % a, exc)
E   sympy.core.sympify.SympifyError: Sympify of expression 'could not parse 'x!'' failed, because of exception being raised:
E   SyntaxError: invalid syntax (<string>, line 1)
=============================== warnings summary ===============================
../../../../../opt/hostedtoolcache/Python/3.12.0-beta.1/x64/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:965: 281199 warnings
  /opt/hostedtoolcache/Python/3.12.0-beta.1/x64/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:965: DeprecationWarning: ast.Str is deprecated and will be removed in Python 3.14; use ast.Constant instead
    inlocs = ast.Compare(ast.Str(name.id), [ast.In()], [locs])

../../../../../opt/hostedtoolcache/Python/3.12.0-beta.1/x64/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:968: 281198 warnings
  /opt/hostedtoolcache/Python/3.12.0-beta.1/x64/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:968: DeprecationWarning: ast.Str is deprecated and will be removed in Python 3.14; use ast.Constant instead
    expr = ast.IfExp(test, self.display(name), ast.Str(name.id))

../../../../../opt/hostedtoolcache/Python/3.12.0-beta.1/x64/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:1102: 63772 warnings
  /opt/hostedtoolcache/Python/3.12.0-beta.1/x64/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:1102: DeprecationWarning: ast.Str is deprecated and will be removed in Python 3.14; use ast.Constant instead
    syms.append(ast.Str(sym))

../../../../../opt/hostedtoolcache/Python/3.12.0-beta.1/x64/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:1104: 63772 warnings
  /opt/hostedtoolcache/Python/3.12.0-beta.1/x64/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:1104: DeprecationWarning: ast.Str is deprecated and will be removed in Python 3.14; use ast.Constant instead
    expls.append(ast.Str(expl))

../../../../../opt/hostedtoolcache/Python/3.12.0-beta.1/x64/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:817: 681080 warnings
  /opt/hostedtoolcache/Python/3.12.0-beta.1/x64/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:817: DeprecationWarning: ast.Str is deprecated and will be removed in Python 3.14; use ast.Constant instead
    keys = [ast.Str(key) for key in current.keys()]

../../../../../opt/hostedtoolcache/Python/3.12.0-beta.1/x64/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:927: 66065 warnings
  /opt/hostedtoolcache/Python/3.12.0-beta.1/x64/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:927: DeprecationWarning: ast.Str is deprecated and will be removed in Python 3.14; use ast.Constant instead
    assertmsg = ast.Str("")

../../../../../opt/hostedtoolcache/Python/3.12.0-beta.1/x64/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:929: 66[176](https://github.com/sympy/sympy/actions/runs/5104236297/jobs/9175208834?pr=25181#step:6:177) warnings
  /opt/hostedtoolcache/Python/3.12.0-beta.1/x64/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:929: DeprecationWarning: ast.Str is deprecated and will be removed in Python 3.14; use ast.Constant instead
    template = ast.BinOp(assertmsg, ast.Add(), ast.Str(explanation))

../../../../../opt/hostedtoolcache/Python/3.12.0-beta.1/x64/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:941: 66164 warnings
  /opt/hostedtoolcache/Python/3.12.0-beta.1/x64/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:941: DeprecationWarning: ast.NameConstant is deprecated and will be removed in Python 3.14; use ast.Constant instead
    clear = ast.Assign(variables, ast.NameConstant(None))

../../../../../opt/hostedtoolcache/Python/3.12.0-beta.1/x64/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:683: 77 warnings
  /opt/hostedtoolcache/Python/3.12.0-beta.1/x64/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:683: DeprecationWarning: ast.Str is deprecated and will be removed in Python 3.14; use ast.Constant instead
    and isinstance(item.value, ast.Str)

../../../../../opt/hostedtoolcache/Python/3.12.0-beta.1/x64/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:685: 77 warnings
  /opt/hostedtoolcache/Python/3.12.0-beta.1/x64/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:685: DeprecationWarning: Attribute s is deprecated and will be removed in Python 3.14; use value instead
    doc = item.value.s

../../../../../opt/hostedtoolcache/Python/3.12.0-beta.1/x64/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:1004: 1063 warnings
  /opt/hostedtoolcache/Python/3.12.0-beta.1/x64/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:1004: DeprecationWarning: ast.Str is deprecated and will be removed in Python 3.14; use ast.Constant instead
    expl_format = self.pop_format_context(ast.Str(expl))

../../../../../opt/hostedtoolcache/Python/3.12.0-beta.1/x64/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:1016: 484 warnings
  /opt/hostedtoolcache/Python/3.12.0-beta.1/x64/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:1016: DeprecationWarning: ast.Num is deprecated and will be removed in Python 3.14; use ast.Constant instead
    expl_template = self.helper("_format_boolop", expl_list, ast.Num(is_or))

sympy/combinatorics/tests/test_permutations.py::test_Permutation
sympy/combinatorics/tests/test_permutations.py::test_Permutation_subclassing
  /home/runner/work/sympy/sympy/sympy/combinatorics/tests/test_permutations.py:150: DeprecationWarning: Bitwise inversion '~' on bool is deprecated. This returns the bitwise inversion of the underlying int object and is usually not what you expect from negating a bool. Use the 'not' operator for boolean negation or ~int(x) if you really want the bitwise inversion of the underlying int.
    assert ~(r**2).is_Identity

sympy/core/tests/test_sympify.py: 38 warnings
  /home/runner/work/sympy/sympy/sympy/parsing/sympy_parser.py:1200: DeprecationWarning: ast.NameConstant is deprecated and will be removed in Python 3.14; use ast.Constant instead
    keywords=[ast.keyword(arg='evaluate', value=ast.NameConstant(value=False, ctx=ast.Load()))],

sympy/core/tests/test_sympify.py::test_evaluate_false
sympy/core/tests/test_sympify.py::test_evaluate_false
sympy/core/tests/test_sympify.py::test_evaluate_false
  /home/runner/work/sympy/sympy/sympy/parsing/sympy_parser.py:1189: DeprecationWarning: ast.Num is deprecated and will be removed in Python 3.14; use ast.Constant instead
    args=[right, ast.UnaryOp(op=ast.USub(), operand=ast.Num(1))],

sympy/core/tests/test_sympify.py::test_evaluate_false
sympy/core/tests/test_sympify.py::test_evaluate_false
sympy/core/tests/test_sympify.py::test_evaluate_false
  /home/runner/work/sympy/sympy/sympy/parsing/sympy_parser.py:1190: DeprecationWarning: ast.NameConstant is deprecated and will be removed in Python 3.14; use ast.Constant instead
    keywords=[ast.keyword(arg='evaluate', value=ast.NameConstant(value=False, ctx=ast.Load()))],

sympy/core/tests/test_sympify.py::test_evaluate_false
sympy/core/tests/test_sympify.py::test_evaluate_false
sympy/core/tests/test_sympify.py::test_evaluate_false
  /home/runner/work/sympy/sympy/sympy/parsing/sympy_parser.py:1170: DeprecationWarning: ast.Num is deprecated and will be removed in Python 3.14; use ast.Constant instead
    args=[ast.UnaryOp(op=ast.USub(), operand=ast.Num(1)), right],

sympy/core/tests/test_sympify.py::test_evaluate_false
sympy/core/tests/test_sympify.py::test_evaluate_false
sympy/core/tests/test_sympify.py::test_evaluate_false
  /home/runner/work/sympy/sympy/sympy/parsing/sympy_parser.py:1171: DeprecationWarning: ast.NameConstant is deprecated and will be removed in Python 3.14; use ast.Constant instead
    keywords=[ast.keyword(arg='evaluate', value=ast.NameConstant(value=False, ctx=ast.Load()))],

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
                                DO *NOT* COMMIT!                                
=========================== short test summary info ============================
FAILED sympy/core/tests/test_sympify.py::test_sympify1 - sympy.core.sympify.SympifyError: Sympify of expression 'could not parse '.[052631578947368421]'' failed, because of exception being raised:
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers (<string>, line 1)
FAILED sympy/core/tests/test_sympify.py::test_sympify_factorial - sympy.core.sympify.SympifyError: Sympify of expression 'could not parse 'x!'' failed, because of exception being raised:
SyntaxError: invalid syntax (<string>, line 1)
= 2 failed, 2649 passed, 129 skipped, 8644 deselected, 35 xfailed, 2 xpassed, 1571[179](https://github.com/sympy/sympy/actions/runs/5104236297/jobs/9175208834?pr=25181#step:6:180) warnings in 755.14s (0:12:35) =
Error: Process completed with exit code 1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions