GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Raise TypeError when calling __new__ unsafely by garychia · Pull Request #4455 · RustPython/RustPython

Conversation

@garychia

@garychia garychia commented Jan 15, 2023

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
image

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
youknowone
youknowone requested changes Jan 15, 2023
View reviewed changes

@youknowone youknowone left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

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!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

garychia reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@garychia

garychia commented Jan 18, 2023

Copy link
Copy Markdown
Contributor Author

I found the following issue in test_ast.py.

image

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

@youknowone youknowone Feb 17, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

PyType_IsSubtype in CPython is same to fast_issubclass in RustPython

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Snowapril Snowapril mentioned this pull request Mar 24, 2023
Fix test_bool test_subclass #4715
Closed
@DimitrisJim

DimitrisJim commented Mar 25, 2023

Copy link
Copy Markdown
Member

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@garychia

garychia commented Mar 25, 2023

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:

RustPython/Lib/test/test_ast.py

Lines 521 to 528 in bbd8fb2

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 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@youknowone youknowone added C-bug Something isn't working A-vm Area: virtual machine labels Mar 28, 2023
@youknowone
youknowone force-pushed the type-new-unsafe branch from bca1776 to 311b7a6 Compare March 30, 2025 04:51
@garychia @youknowone
Raise TypeError when calling __new__ unsafely
36b6755
@youknowone
youknowone force-pushed the type-new-unsafe branch from 311b7a6 to 36b6755 Compare April 7, 2025 08:42
@ShaharNaveh ShaharNaveh mentioned this pull request Dec 16, 2025
flag: DISALLOW_INSTANTIATION #6445
Merged
@youknowone youknowone closed this in #6445 Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@youknowone youknowone youknowone requested changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

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

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@garychia @DimitrisJim @youknowone
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.