Skip to content

Preserve floating-point results of negative integer powers - #640

Open
fhgffy wants to merge 1 commit into
python-poetry:masterfrom
fhgffy:fix/integer-negative-powers-20261009
Open

fhgffy wants to merge 1 commit into
python-poetry:masterfrom
fhgffy:fix/integer-negative-powers-20261009

Conversation

@fhgffy

@fhgffy fhgffy commented Oct 9, 2026 •

Copy link
Copy Markdown

Summary

Negative powers of integer items currently disagree with their serialized value: item(2) ** -1 compares equal to 0, but renders as 0.5. Fractional exponents also raise instead of allowing Python's reflected float operation.

Keep floating-point power results as Float items and pass NotImplemented back to Python for reflected dispatch. Positive and modular integer powers retain their existing result type.

Tests: 12 new cases pass (7 fail on the original implementation); the complete suite passes with 1109 tests on Python 3.12. Ruff and formatting checks pass, and both wheel and sdist build. Mypy reports the same five pre-existing errors on the original and patched source.

The downstream Poetry integration fails one extraction assertion on Python 3.12.15. A controlled replay with the official tarfile modules reproduces the difference without importing tomlkit: 3.12.15 normalizes the path and writes safely inside the destination, while the unchanged Poetry test expects OutsideDestinationError. The test expectation is addressed in python-poetry/poetry#11133.

Agent Drafting Metadata

  • Agent: Codex
  • Model: GPT-6
  • Notes: Assisted with investigation, the patch and regression tests.

@fhgffy

fhgffy commented Oct 12, 2026

Copy link
Copy Markdown
Author

The failing Poetry tarfile regression test has been fixed upstream in python-poetry/poetry#11133, which is now merged. The failed Integration Tests run is still from October 9. Could you rerun it?

@Wkhanex Wkhanex left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

65 direct/reflected power checks matched Python numeric behavior for bases -10, -2, -1, 0, 1, 2 and 10 with negative/zero/positive exponents, float-base reflected dispatch, and zero-to-negative-power errors. I also checked the explicit integer reflected-power method and a custom __rpow__ operand. I used Python 3.12.14 against commit 7630f26.

Successful TOML wrapper results re-parsed to the same value with stdlib tomllib. In particular, tomlkit.item(2) ** -1 stays 0.5 rather than truncating to 0, and tomlkit.item(2) ** Reflected() reaches the custom operand after NotImplemented. Normal float-base dispatch can return a plain float, as Python does. These standalone assertions use fetched PR source; I did not run the full pytest/type-check suite.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants