Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 6, 2026

Class __dict__.get("__new__") returned the raw function instead of the staticmethod wrapper, diverging from CPython.

  • Behavior alignment
    • During type creation, wrap user-defined __new__ functions in staticmethod so class and nested-class dictionaries expose the CPython-compatible descriptor.
  • Regression coverage
    • Added snippet assertions to verify ClassWithNew.__dict__.get("__new__") (and nested variants) yields a staticmethod.
    • Unmarked test_test_simple_enum expectedFailure now that it passes, keeping enum behavior in parity with CPython.

Example:

class Test:
    def __new__(cls):
        return super().__new__(cls)

assert isinstance(Test.__dict__.get("__new__"), staticmethod)
Original prompt

This section details on the original issue you should resolve

<issue_title>Special methods</issue_title>
<issue_description>## Feature

Using Class.dict.get() will wrap special methods. I noticed this when trying to update the http module.

Example:

class TestClass:
    def __new__(cls, value, phrase, description=''):
        pass

RustPython

>>>>> TestClass.__dict__.get("__new__")
<function TestClass.__new__ at 0x55cee9f8f810>

CPython

>>> TestClass.__dict__.get("__new__")
<staticmethod(<function TestClass.__new__ at 0x7f6444dd4ea0>)>

Python Documentation or reference to CPython source code

https://docs.python.org/3/reference/datamodel.html#object.__new__</issue_description>

<agent_instructions>Investigate why does this happens. Add the cpython behavior to builtin_type.py and try to fix it.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 6, 2026

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI changed the title [WIP] Fix behavior of special methods in Class.__dict__.get() Ensure __new__ entries in class __dict__ are staticmethods Jan 6, 2026
Copilot AI requested a review from youknowone January 6, 2026 00:40
@youknowone youknowone marked this pull request as ready for review January 6, 2026 01:06
@youknowone
Copy link
Member

@copilot check CI result, remove expectedFailure mark from UNEXPECTED SUCCESS: test_test_simple_enum (test.test_enum.TestStdLib.test_test_simple_enum)

Co-authored-by: youknowone <[email protected]>
Copy link
Contributor Author

Copilot AI commented Jan 6, 2026

@copilot check CI result, remove expectedFailure mark from UNEXPECTED SUCCESS: test_test_simple_enum (test.test_enum.TestStdLib.test_test_simple_enum)

Removed the expectedFailure marker from test_test_simple_enum in 662bbd2 and the test now passes in a targeted run.

@youknowone youknowone merged commit 03380dc into main Jan 6, 2026
13 checks passed
@youknowone youknowone deleted the copilot/fix-special-methods-behavior branch January 6, 2026 03:16
terryluan12 pushed a commit to terryluan12/RustPython that referenced this pull request Jan 15, 2026
…n#6659)

* Initial plan

* Wrap __new__ methods as staticmethods in type dicts

Co-authored-by: youknowone <[email protected]>

* Unmark passing enum test

Co-authored-by: youknowone <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: youknowone <[email protected]>
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.

Special methods

2 participants