Skip to content

Respect zero fractional digits for positive pyfloat fallback - #2473

Open
FanWu-ai wants to merge 1 commit into
joke2k:masterfrom
FanWu-ai:fix/positive-pyfloat-zero-digits
Open

FanWu-ai wants to merge 1 commit into
joke2k:masterfrom
FanWu-ai:fix/positive-pyfloat-zero-digits

Conversation

@FanWu-ai

@FanWu-ai FanWu-ai commented Oct 5, 2026

Copy link
Copy Markdown

What does this change

Keep pyfloat(right_digits=0, positive=True) integer-valued when a zero draw needs to be made positive.

What was wrong

The fallback added sys.float_info.epsilon, producing 2.220446049250313e-16 despite the requested zero fractional digits. For example, Faker.seed(31) followed by Faker().pyfloat(left_digits=1, right_digits=0, positive=True) reproduces it.

This is the remaining zero-digit case of the precision problem reported in #1402 and addressed for nonzero fractional precision in #1406. #428 established that right_digits=0 generates integer values represented as floats.

How this fixes it

Use 1.0, the smallest positive integer-valued float, for this fallback. Positive fractional-precision handling and nonzero results are unchanged. Four deterministic regression cases cover one/two integer digits and both unrestricted and max_value=1 calls.

Validation

  • All four new regression cases fail against the unchanged implementation and pass with this fix.
  • Untouched baseline: 2,412 tests, 10 upstream skips, 10 subtests; separate session-override run: 8 passed.
  • Final complete suite on CPython 3.12.14: 2,416 tests, the same 10 upstream skips, 10 subtests; separate session-override run: 8 passed; 96% coverage. Eight initial skips are the session-override cases run separately; the other two are Windows-only tests.
  • tox -e flake8,isort,mypy,doc8,checkmanifest,black,py312 passed.
  • Required make lint under CPython 3.11.16 passed, including stub generation; no generated-file changes remain.
  • python scripts/check_test_class_order.py and git diff --check passed.
  • A separate AI reviewer inspected the change and independently reran both complete test commands with the same passing counts, plus boundary controls.

AI Assistance Disclosure (REQUIRED)

  • If AI tools were used, I have disclosed which ones, and fully reviewed and verified their output.

OpenAI Codex was used for source inspection, implementation, regression tests, independent AI review, and this description. The exact model version is unavailable in this session. All stated checks were actually executed. No human review is claimed. This is a correctness fix, with no vulnerability or exploit claim.

Checklist

  • I have read the contribution guidelines.
  • I have read the coding-style guidelines.
  • I have run make lint.

@FanWu-ai
FanWu-ai marked this pull request as ready for review October 5, 2026 05:46
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.

1 participant