Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-128509: AddPyUnstable_IsImmortal for finding immortal objects#129182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
encukou merged 16 commits intopython:mainfromZeroIntensity:unstable-is-immortal
Jan 27, 2025

Conversation

@ZeroIntensity
Copy link
Member

@ZeroIntensityZeroIntensity commentedJan 22, 2025
edited
Loading

ZeroIntensityand others added4 commitsJanuary 22, 2025 12:06
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Victor Stinner <vstinner@python.org>
Copy link
Member

@vstinnervstinner left a comment

Choose a reason for hiding this comment

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

colesbury reacted with thumbs up emoji
@ZeroIntensity
Copy link
MemberAuthor

I think@encukou's review would also be helpful.

staticPyObject*
is_immortal(PyObject*self,PyObject*op)
{
returnPyBool_FromLong(PyUnstable_IsImmortal(op));

Choose a reason for hiding this comment

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

Suggested change
returnPyBool_FromLong(PyUnstable_IsImmortal(op));
NULLABLE(op)
returnPyLong_FromLong(PyUnstable_IsImmortal(op));

This allows to test with NULL, and check if the result is not 0 or 1.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I think it makes sense to crash withNULL.

encukou reacted with thumbs up emoji
fornon_immortalinnon_immortals:
withself.subTest(non_immortal=non_immortal):
self.assertFalse(_testcapi.is_immortal(non_immortal))

Choose a reason for hiding this comment

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

Does_testcapi.is_immortal(NULL) crash? If yes, add a comment, otherwise add a test.

Copy link
Member

Choose a reason for hiding this comment

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

If yes, add a comment

And ideally anassert to the implementation (as “executable documentation”).

ZeroIntensity reacted with thumbs up emoji
fornon_immortalinnon_immortals:
withself.subTest(non_immortal=non_immortal):
self.assertFalse(_testcapi.is_immortal(non_immortal))

Copy link
Member

Choose a reason for hiding this comment

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

If yes, add a comment

And ideally anassert to the implementation (as “executable documentation”).

ZeroIntensity reacted with thumbs up emoji
ZeroIntensityand others added4 commitsJanuary 23, 2025 08:03
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
withself.subTest(non_immortal=non_immortal):
self.assertFalse(_testcapi.is_immortal(non_immortal))

# CRASHES _testcapi.is_immortal(NULL)

Choose a reason for hiding this comment

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

Did you test this?

Copy link
Member

Choose a reason for hiding this comment

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

is_immortal(None) checks ifNone is immortal, it doesn't crash.

I suggest to remove this comment. I don't think that it's worth it to bother with testing NULL,PyUnstable_IsImmortal() now starts withassert(op != NULL);. And it's interesting to test if None is immortal or not.

Choose a reason for hiding this comment

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

I suggest to apply my suggestions to be able to test with NULL.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

That would break the test withNone. I think as long as we have the assertion there, it's not worth explicitly testing it.

Copy link
Member

@vstinnervstinner left a comment

Choose a reason for hiding this comment

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

classTestCAPI(unittest.TestCase):deftest_immortal_builtins(self):_testcapi.test_immortal_builtins()deftest_immortal_small_ints(self):_testcapi.test_immortal_small_ints()

There is a problem with existing tests: all methods calledtest_xxx are run automatically bytest_capi.test_misc:

vstinner@mona$ ./python -m test test_capi -v -m test_immortal_small_ints(...)test_immortal_small_ints (test.test_capi.test_immortal.TestCAPI.test_immortal_small_ints) ... oktest_immortal_small_ints (test.test_capi.test_misc.Test_testcapi.test_immortal_small_ints) ... ok(...)

Tests are run twice. Can you fix these tests as part of your PR? Just use a different function name prefix, such ascheck_xxx.

ZeroIntensity reacted with thumbs up emoji


staticPyObject*
is_immortal(PyObject*self,PyObject*op)
Copy link
Member

Choose a reason for hiding this comment

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

Oh, I didn't know thatModules/_testcapi/immortal.c exists. Maybe put the new function there?

ZeroIntensity reacted with thumbs up emoji
Copy link
Member

@vstinnervstinner left a comment

Choose a reason for hiding this comment

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

LGTM

@encukouencukou merged commit3fb5f6e intopython:mainJan 27, 2025
41 checks passed
@ZeroIntensityZeroIntensity deleted the unstable-is-immortal branchJanuary 27, 2025 15:42
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@vstinnervstinnervstinner approved these changes

@encukouencukouAwaiting requested review from encukou

@serhiy-storchakaserhiy-storchakaAwaiting requested review from serhiy-storchaka

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@ZeroIntensity@vstinner@encukou@serhiy-storchaka

[8]ページ先頭

©2009-2025 Movatter.jp