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

Skip to content

Have a PySelf ref type to improve error messages for invalid arg counts to methods #741

Open
@coolreader18

Description

@coolreader18

This is probably only once arbitrary_self_types, lands, but in CPython if you do

>>> l = []
>>> l.append()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: append() takes exactly one argument (0 given)
>>> list.append()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: descriptor 'append' of 'list' object needs an argument

The error messages are different, to indicate the different kinds of arguments that are missing (self vs normal argument). Whereas in RustPython:

>>>>> l = []
>>>>> l.append()
Traceback (most recent call last):
  File <stdin>, line 0, in <module>
TypeError: Expected at least 2 arguments (1 given)
>>>>> list.append()
Traceback (most recent call last):
  File <stdin>, line 0, in <module>
TypeError: Expected at least 2 arguments (0 given)

So you'd probably do something like

impl PyListRef {
    fn append(self: PySelf<PyList>, ...) { ... }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-designAbout RustPython's own implementationA-vmArea: virtual machineC-compatA discrepancy between RustPython and CPython

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions