Skip to content

Python 3.10/3.11: bonds package fails to import — multi-line f-string needs 3.12 (declared support is >=3.10) #248

Closed

Description

@DMZ22

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:

  1. Put the replacement field on one line (one-line change) — keeps 3.10/3.11 support; or
  2. 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.

Activity

  1. sanjey99 commented on Jul 24, 2026

    @sanjey99
    Contributor

    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.

  2. DMZ22 commented on Jul 24, 2026

    @DMZ22
    ContributorAuthor

    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:

    • pyproject.toml declares requires-python = ">=3.10,<3.14", i.e. 3.10 / 3.11 / 3.12 / 3.13.
    • 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.

  3. domokane commented on Aug 6, 2026

    @domokane
    Collaborator

    I am considering rolling financepy to be compatible with Python 3.12. Would this be a solution ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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