Skip to content

gh-148868: Increase test coverage for cmath.isinf#148869

Open
manoj-km24 wants to merge 2 commits intopython:mainfrom
manoj-km24:add-test-cmath
Open

gh-148868: Increase test coverage for cmath.isinf#148869
manoj-km24 wants to merge 2 commits intopython:mainfrom
manoj-km24:add-test-cmath

Conversation

@manoj-km24
Copy link
Copy Markdown
Contributor

@manoj-km24 manoj-km24 commented Apr 22, 2026

This PR adds additional test cases for the isinf() function in cmath library.
The test cases are verified from the below snippet:

>>> import cmath
>>> inf = float('inf')
>>> cmath.isinf(-inf)
True
>>> cmath.isinf(inf/inf)
False

Comment thread Lib/test/test_cmath.py Outdated
self.assertFalse(cmath.isinf(NAN))
self.assertTrue(cmath.isinf(INF))
self.assertTrue(cmath.isinf(-INF))
self.assertFalse(cmath.isinf(INF/INF))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why this? INF/INF is NaN so it does not make any sense

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

INF/INF seems to be an exception because when we take INF + INF and INF * INF , they produce INF but on the other hand INF/INF produces NaN. So I thought it would be worth testing that too . I could change it if you like

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It is not an exception, it is what the standard expects (and what maths tells you about). Adding two infinities or multiplying result in an infinity. However division and subtration of infinities do not have a limit hence a NaN. Please make sure you understand the issue before creating one and opening a PR in the future.

So, remove this case. You can keep the -INF one but I do not really think it is worth. In particular we want to check that isinf from math (and not cmath) also checks negative infinity.

Copy link
Copy Markdown
Contributor Author

@manoj-km24 manoj-km24 Apr 22, 2026

Choose a reason for hiding this comment

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

Will do . Sorry , i misused the word "exception". What I wanted to say was if in case we change the behaviour of INF, would it be better if we check what subtracting or dividing 2 infinities produces , as the standard expects since addition and multiplication of 2 infinities are obvious. Just a doubt ,I will clear the INF/INF case in a minute.

@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented Apr 22, 2026

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@picnixz picnixz changed the title gh-148868: Add additional edge case tests for cmath.py gh-148868: Increase test coverage for cmath.isinf Apr 22, 2026
@manoj-km24
Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again.

@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented Apr 22, 2026

Thanks for making the requested changes!

@picnixz: please review the changes made to this pull request.

@bedevere-app bedevere-app Bot requested a review from picnixz April 22, 2026 10:51
@picnixz
Copy link
Copy Markdown
Member

picnixz commented Apr 22, 2026

Do we test math.isinf(-INF)? if not please add that test case as well

@picnixz
Copy link
Copy Markdown
Member

picnixz commented Apr 22, 2026

And Sergey said that we already cover signed cases elsewhere so I am unsure whether this really adds value.

@manoj-km24
Copy link
Copy Markdown
Contributor Author

manoj-km24 commented Apr 22, 2026

And Sergey said that we already cover signed cases elsewhere so I am unsure whether this really adds value.

As Sergey said , The test is covered in test_math.py (-inf) . Should I keep it in test_cmath.py ?

@picnixz
Copy link
Copy Markdown
Member

picnixz commented Apr 22, 2026

If test_math tests math.isinf(-inf) then we can indeed add your test. I think we could have cleaner tests with a bit more loops and subtests but this would be a bit churn.

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

Labels

awaiting merge skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants