Repository navigation
Narrow real math and cmath constants to float - #16886
Merged
Merged
Conversation
Signed-off-by: wangshun <96341168+xixi-box@users.noreply.github.com>
srittau
requested changes
Nov 21, 2026
srittau
left a comment
Collaborator
There was a problem hiding this comment.
Please remove the tests. In typeshed, we only add regression tests for functions and classes which are known to have caused complex problems in the past, or where stubs are difficult to get right. 100% test coverage for typeshed is neither necessary nor desirable, as it would lead to code duplication.
See tests/REGRESSION.md for more information.
This comment has been minimized.
This comment has been minimized.
Contributor
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
srittau
approved these changes
Nov 21, 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.
Fixes #16059
The bulk FloatInt migration made type checkers infer
float | intfore,pi,inf,nan, andtauin both modules, although CPython creates each as a float. CPython math initialization and CPython cmath initialization.Declare these constants as
Final[float]so callers get the precise type and can use float-specific methods directly.Tests:
.venv/bin/python -m pyright -p pyrightconfig.testcases.json --pythonversion 3.10 stdlib/@tests/test_cases/check_math.py stdlib/@tests/test_cases/check_cmath.py.Result: Before adding the regression, .venv/bin/python -m pyright -p pyrightconfig.testcases.json --pythonversion 3.10 stdlib/@tests/test_cases/check_math.py passed with 0 errors.
Result: Before adding the regression, .venv/bin/python tests/regr_test.py stdlib --python-version 3.10 3.14 passed on Linux.
Result: Base regression command exited 1 with ten assert_type mismatches, five in check_math.py and five in check_cmath.py (OSSCOUT_BASE.log).
Result: Patched regression command exited 0 with 0 errors (OSSCOUT_PATCHED.log).
Result: Patched .venv/bin/python tests/regr_test.py stdlib --python-version 3.10 3.14 passed on Linux (OSSCOUT_PATCHED_MYPY.log).
Result: Patched .venv/bin/python tests/mypy_test.py stdlib/math stdlib/cmath.pyi --python-version 3.10 3.14 passed (OSSCOUT_PATCHED_STUB_MYPY.log).
Result: Patched .venv/bin/python -m pyright -p pyrightconfig.stricter.json --pythonversion 3.10 stdlib/math stdlib/cmath.pyi passed with 0 errors (OSSCOUT_PATCHED_STUB_PYRIGHT.log).
Result: Patched .venv/bin/python -m mypy.stubtest --custom-typeshed-dir . --strict-type-check-only math cmath passed with no issues in 2 modules (OSSCOUT_PATCHED_STUBTEST.log).
Result: With .venv activated, python tests/ty_test.py stdlib/cmath.pyi --python-version 3.10 --platform linux --python .venv/bin/python and python tests/pyrefly_test.py stdlib/cmath.pyi --python-version 3.10 --platform linux --python .venv/bin/python passed. Initial attempts without the virtual environment on PATH could not locate the checker executables. The retries are in OSSCOUT_PATCHED_CMATH_TY_RETRY.log and OSSCOUT_PATCHED_CMATH_PYREFLY_RETRY.log.
Result: Patched .venv/bin/pre-commit run --files stdlib/math/init.pyi stdlib/cmath.pyi stdlib/@tests/test_cases/check_math.py stdlib/@tests/test_cases/check_cmath.py passed all applicable hooks (OSSCOUT_PATCHED_PRECOMMIT.log).
Regression coverage:
stdlib/@tests/test_cases/check_cmath.py.Prepared by Codex.