lmfit / asteval

minimalistic evaluator of python expression using ast module
https://lmfit.github.io/asteval
MIT License
183 stars 41 forks source link

Python 3.10: test_kaboom fails with IndexError #92

Closed musicinmybrain closed 3 years ago

musicinmybrain commented 3 years ago

Fedora Linux is currently doing a mass rebuild of Python packages in Rawhide (the development version of Fedora) using Python 3.10.0 beta 2. The build of python-asteval is failing on Python 3.10 as follows:

=================================== FAILURES ===================================
_____________________________ TestEval.test_kaboom _____________________________
self = <test_asteval.TestEval testMethod=test_kaboom>, chk_type = 'MemoryError'
chk_msg = ''
    def check_error(self, chk_type='', chk_msg=''):
        try:
>           errtype, errmsg = self.interp.error[0].get_error()
E           IndexError: list index out of range
tests/test_asteval.py:126: IndexError
During handling of the above exception, another exception occurred:
self = <test_asteval.TestEval testMethod=test_kaboom>
        def test_kaboom(self):
            """ test Ned Batchelder's 'Eval really is dangerous' - Kaboom test (and related tests)"""
            self.interp("""(lambda fc=(lambda n: [c for c in ().__class__.__bases__[0].__subclasses__() if c.__name__ == n][0]):
        fc("function")(fc("code")(0,0,0,0,"KABOOM",(),(),(),"","",0,""),{})()
    )()""")
            self.check_error('NotImplementedError', 'Lambda')  # Safe, lambda is not supported

            self.interp(
                """[print(c) for c in ().__class__.__bases__[0].__subclasses__()]""")  # Try a portion of the kaboom...

            self.check_error('AttributeError', '__class__')  # Safe, unsafe dunders are not supported
            self.interp("9**9**9**9**9**9**9**9")
            self.check_error('RuntimeError')  # Safe, safe_pow() catches this
            self.interp(
                "x = ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((1))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))")
            if version_info == (3, 9):
                self.isvalue('x', 1)
                self.check_error(None)
            else:
>               self.check_error('MemoryError')  # Hmmm, this is caught, but its still concerning...
tests/test_asteval.py:922: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/test_asteval.py:132: in check_error
    self.assertTrue(False)
E   AssertionError: False is not true
=========================== short test summary info ============================
FAILED tests/test_asteval.py::TestEval::test_kaboom - AssertionError: False i...
========================= 1 failed, 61 passed in 1.38s =========================

See https://bugzilla.redhat.com/show_bug.cgi?id=1899470.

newville commented 3 years ago

@musicinmybrain thanks for the report - now fixed, added testing for Python 3.10, and will push out a release soon.

musicinmybrain commented 3 years ago

Are you still planning to push out a release soon, or should we backport a patch from https://github.com/newville/asteval/commit/639bbfca6e0d9f761a473ab40eceffa7252c1a3a to Fedora for now? No pressure—just wondering.

newville commented 3 years ago

@musicinmybrain tagged and pushed 0.9.24 to PyPI

musicinmybrain commented 3 years ago

Thanks! I’ve sent a PR to the maintainer of the Fedora package to update to 0.9.25.