FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Raise TypeError when calling __new__ unsafely by garychia · Pull Request #4455 · RustPython/RustPython · GitHub

Raise TypeError when calling __new__ unsafely - #4455

Closed
garychia wants to merge 1 commit into
RustPython:mainfrom
garychia:type-new-unsafe
Closed

Raise TypeError when calling __new__ unsafely#4455
garychia wants to merge 1 commit into
RustPython:mainfrom
garychia:type-new-unsafe

Conversation

Copy link
Copy Markdown
Contributor

Related to #3692
This implementation is based on the following code from CPython.
https://github.com/python/cpython/blob/206f05a46b426eb374f724f8e7cd42f2f9643bb8/Objects/typeobject.c#L7685-L7700

youknowone left a comment

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

CI Failure came from successful test.

test_subclass (test.test_bool.BoolTest) ... unexpected success

Because you fixed the bug, you can remove @unittest.expectedFailure decorator from the test.

Thank you!

Copy link
Copy Markdown
Contributor Author

I found the following issue in test_ast.py.

But I'm sure if it is related to my code. It seems that typ in call_slot_new is set to object instead of Constant for some reason.

Comment thread vm/src/builtins/type.rs Outdated
}
}
if let Some(ref basetype) = staticbase {
if !PyType::subclasscheck(basetype.to_owned(), typ.to_owned()) {

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

PyType_IsSubtype in CPython is same to fast_issubclass in RustPython

Copy link
Copy Markdown
Member

Hey @garychia do you still have time/want to work on this?

Copy link
Copy Markdown
Contributor Author

Hi, @DimitrisJim! I was struggling to solve the problem that happens when running the test_ast test as I mentioned before. Based on my observation, RustPython tried to construct an N object by using object.__new__, which is not safe. But I have no idea why it behaved this way and whether it relates to my code.
This piece of code triggered the problem:

class N(ast.Num):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.z = 'spam'
class N2(ast.Num):
pass
n = N(42)

youknowone added C-bug Something isn't working A-vm Area: virtual machine labels Mar 28, 2023
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

Labels

A-vm Area: virtual machine C-bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL