You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python 3.10/3.11: bonds package fails to import — multi-line f-string needs 3.12 (declared support is >=3.10) #248
financepy/products/bonds/bond.py line 1238 contains an f-string whose replacement field spans two lines:
print(f"Warning: YTM calculation did not converge for price {dirty_price}")
Multi-line expressions inside f-strings are a PEP 701 feature, available only on Python 3.12+. On Python 3.10 and 3.11 this is a SyntaxError at import time:
File ".../financepy/products/bonds/bond.py", line 1238
SyntaxError: unterminated string literal (detected at line 1238)
and it takes down the whole financepy.products.bonds package (its __init__.py imports bond), plus everything that imports bonds transitively — on 3.11, 17 unit-test modules fail collection for this reason (that's how I ran into it while testing #247).
Why it slips through:
pyproject.toml declares requires-python = ">=3.10,<3.14", so pip installs happily on 3.10/3.11 where the import then fails.
run-unit-tests.yml pins a single PYTHON_VERSION: '3.13.9', so CI never exercises the older interpreters. The line came in with e38db05 (Nov 2025).
Fix options:
Put the replacement field on one line (one-line change) — keeps 3.10/3.11 support; or
Declare reality and bump requires-python to >=3.12.
If you'd like option 1, happy to send the trivial PR; adding the minimum supported version to the CI matrix would keep this from regressing either way.
hi, i'd like to work on this. going with fix option 1 (keep the replacement field on one line, so 3.10/3.11 stays supported). also found a second instance of the same bug at line ~1548 (OAS warning) that wasn't in the original report, fixing that too. will send a pr shortly.
Great, it's all yours @sanjey99 — and your second find is real. Confirming the exact locations, since a partial fix here is easy to ship by accident: compile() stops at the first SyntaxError in a file, so the second one stays invisible until the first is patched.
I scanned every .py in the package for f-strings whose replacement field spans a newline (the PEP 701 construct that needs ≥3.12). There are exactly two, both in financepy/products/bonds/bond.py:
1238 — print(f"Warning: YTM calculation did not converge for price { → dirty_price}")
1549 — print(f"Warning: OAS calculation did not converge for price { → dirty_price}")
Nothing else in the package trips a 3.11 parse, so joining those two onto one line each is the complete fix.
Worth flagging separately, because it explains why this reached a release at all — the CI cannot catch it:
run-unit-tests.yml and run-golden-tests.yml both pin PYTHON_VERSION: '3.13.9' — the only declared-supported version where this syntax is legal.
pylint.yml runs on 3.8, which is below the declared floor.
docs.yml is the only job on 3.11, and it would have caught this. But it triggers on push: branches: [main], and the repository's only branch is master — so it has never executed. gh run list --workflow=docs.yml returns nothing at all.
So a python-version matrix of at least ["3.10", "3.13"] on the unit-test workflow would stop this class of regression permanently, and repointing docs.yml at master would fix a workflow that is currently dead. Both are separate from your fix — happy to send either as its own PR if the maintainer wants, but I don't want to get in the way of yours.
Activity
sanjey99 commentedon Jul 24, 2026
hi, i'd like to work on this. going with fix option 1 (keep the replacement field on one line, so 3.10/3.11 stays supported). also found a second instance of the same bug at line ~1548 (OAS warning) that wasn't in the original report, fixing that too. will send a pr shortly.
DMZ22 commentedon Jul 24, 2026
Great, it's all yours @sanjey99 — and your second find is real. Confirming the exact locations, since a partial fix here is easy to ship by accident:
compile()stops at the firstSyntaxErrorin a file, so the second one stays invisible until the first is patched.I scanned every
.pyin the package for f-strings whose replacement field spans a newline (the PEP 701 construct that needs ≥3.12). There are exactly two, both infinancepy/products/bonds/bond.py:print(f"Warning: YTM calculation did not converge for price {→dirty_price}")print(f"Warning: OAS calculation did not converge for price {→dirty_price}")Nothing else in the package trips a 3.11 parse, so joining those two onto one line each is the complete fix.
Worth flagging separately, because it explains why this reached a release at all — the CI cannot catch it:
pyproject.tomldeclaresrequires-python = ">=3.10,<3.14", i.e. 3.10 / 3.11 / 3.12 / 3.13.run-unit-tests.ymlandrun-golden-tests.ymlboth pinPYTHON_VERSION: '3.13.9'— the only declared-supported version where this syntax is legal.pylint.ymlruns on 3.8, which is below the declared floor.docs.ymlis the only job on 3.11, and it would have caught this. But it triggers onpush: branches: [main], and the repository's only branch ismaster— so it has never executed.gh run list --workflow=docs.ymlreturns nothing at all.So a
python-versionmatrix of at least["3.10", "3.13"]on the unit-test workflow would stop this class of regression permanently, and repointingdocs.ymlatmasterwould fix a workflow that is currently dead. Both are separate from your fix — happy to send either as its own PR if the maintainer wants, but I don't want to get in the way of yours.domokane commentedon Aug 6, 2026
I am considering rolling financepy to be compatible with Python 3.12. Would this be a solution ?