Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix test_bool test_subclass #4715

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

minhrongcon2000
Copy link
Contributor

@minhrongcon2000 minhrongcon2000 commented Mar 18, 2023

Fix unsafe __new__ for int function

@youknowone youknowone force-pushed the fix/not_allow_init_int branch from 2b03849 to 9ede5fd Compare March 21, 2023 05:41
Copy link
Member

@youknowone youknowone left a comment

Choose a reason for hiding this comment

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

Thank you for contributing, but this fix doesn't seem to correct implementation.

Could you check corresponding cpython implementation?
https://github.com/python/cpython/blob/main/Objects/typeobject.c#L7694-L7701

@minhrongcon2000
Copy link
Contributor Author

Sure! I will check it when I have time :D

@minhrongcon2000
Copy link
Contributor Author

minhrongcon2000 commented Mar 23, 2023

@youknowone The block of code that you show me in the previous comment is to check whether cls is a subtype of the current class that called __new__. In CPython, however, bool is a subtype of int and in CPython, int is not allowed to call __new__ with subtype as well. See https://github.com/python/cpython/blob/87be8d95228ee95de9045cf2952311d20dc5de45/Objects/typeobject.c#L7711-L7718

I will fix it in the next commit

@youknowone
Copy link
Member

Oh, i am sorry. I left wrong link

@Snowapril
Copy link
Contributor

Oh .... It seems duplicate PR exist here #4455 😭 (cc. @youknowone )

@DimitrisJim
Copy link
Member

yeah and that PR goes about things in the approach CPython has by modifying type.__new__ to catch this.

@minhrongcon2000
Copy link
Contributor Author

Oh! So I will close this PR now :D

@DimitrisJim
Copy link
Member

we should just coordinate with garychia and see if they still want to work on it, I'll leave a comment there to check. If they don't have time, you can take inspiration from their approach πŸ˜„

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.

4 participants