Open
Description
Feature
<built-in type>.__new__(<other built-in type>)
raise TypeError
.
(Maybe 'built-in type' is not a exact definition because object.__new__(_frozen_importlib.BuiltinImporter)
is valid in CPython.)
CPython:
>>> a = object.__new__(dict)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: object.__new__(dict) is not safe, use dict.__new__()
RustPython:
>>>>> a = object.__new__(dict) # This doen't raise TypeError
>>>>> repr(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: Expected payload 'dict' but 'dict' found
>>>>> str(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: Expected payload 'dict' but 'dict' found
Most of cases are above,
but when bool
is passed as argument, it is panicked.
>>>>> a = object.__new__(bool)
>>>>> a
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', vm\src\builtins\bool.rs:188:29
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process didn't exit successfully: `C:\Users\user\RustPython\target\release\rustpython.exe` (exit code: 101)
Python Documentation
Relevant code in RustPython:
RustPython/vm/src/builtins/type.rs
Line 227 in 996250d