Fix NameError in F_PSignature on Python 3.13 (#179)#194
Merged
Conversation
…and read them in a second exec() call. This worked on older Python because both exec() calls shared the same locals dict, but Python 3.13 changed locals() to return a fresh snapshot each call, so the second exec couldn't see what the first one defined.
khasawn3
approved these changes
Jun 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The
F_PSignaturefunction usedexec()to create dynamically-named local variables and read them in a secondexec()call. This worked on older Python because bothexec()calls shared the same locals dict, but Python 3.13 changedlocals()to return a fresh snapshot each call (PEP 667), so the secondexeccouldn't see what the first one defined.The fix replaces the two
exec()calls with a regular Python list of sympy expressions indexed by segment. No string templating, no scope tricks, and the math is unchanged.Motivation and Context
Fixes #179. The path signature classification example from the docs (https://teaspoontda.github.io/teaspoon/modules/ML/CL_PS.html) crashes on Python 3.13 with
NameError: name 'f_1_1_case1' is not defined, which makes the documented workflow unusable on the latest Python.How has this been tested?
NameErroron Python 3.13.13 using the upstreamteaspoon1.5.30 from pip.CL_PSexample end-to-end on Python 3.13.13.L=[1]and 23 diagrams withL=[1,2]: max absolute difference is0.0(bitwise identical).sympy.simplify(difference is0).tests/test_classification.pyandtests/test_featureFunctions.py(4 passed).Types of changes
Checklist
make clean)make html)pyproject.tomlfile.make tests)