Skip to content

BuiltinFunctionType and BuiltinMethodType are different #3100

Closed

Description

@Tetramad

Feature

types.BuiltinFunctionType must be equal to types.BuiltinMethodType.
In other word, types returned by builtin function and types returned by builtin method must be of the same type.

In CPython

>>> import types
>>> types.BuiltinFunctionType == types.BuiltinMethodType
True
>>> type(len) == type([].append)
True

In RustPython

>>>>> import types
>>>>> types.BuiltinFunctionType == types.BuiltinMethodType
False
>>>>> type(len) == type([].append)
False

Python Documentation

BuiltinFunctionType and BuiltinMethodType have same descriptions.
Also, commented at source code.

Activity

  1. DimitrisJim commented on Sep 21, 2021

    @DimitrisJim
    Member

    Note: I think must be equal is a bit too strong in this case, I don't believe there's a requirement that these be equal. It would be nice if they would, though.

  2. changed the title [-]compatible issue: `BuiltinFunctionType` and `BuiltinMethodType` are different[/-] [+]`BuiltinFunctionType` and `BuiltinMethodType` are different[/+] on Sep 21, 2021
  3. Tetramad commented on Sep 21, 2021

    @Tetramad
    ContributorAuthor

    Sorry for my bad english. I can't find words other than 'must be', 'should be'.
    "It would be nice if they would", that's what I wanted to say. ;)

  4. youknowone commented on Oct 6, 2021

    @youknowone
    Member

    Roughly, adding zelf: Option<PyObjectRef> to PyBuiltinFunction and replacing PyBoundMethod to PyBuiltinFunction will solve it.

    It looks like a good next-step issue for who understand how python binding works and finished a few good first issues.

  5. Snowapril commented on Jul 6, 2022

    @Snowapril
    Contributor

    @youknowone This issue seems fixed.

    >>>>> import types
    >>>>> types.BuiltinFunctionType == types.BuiltinMeth
    odType
    False
    >>>>> type(len) == type([].append)
    False

    Oh sorry, my mistake

  6. moreal commented on Jul 25, 2022

    @moreal
    Contributor

    I'm working on this issue. I left this comment to avoid task conflicts.

  7. seungha-kim commented on Mar 9, 2023

    @seungha-kim
    Contributor

    I'll take a look!

  8. youknowone commented on Apr 17, 2023

    @youknowone
    Member

    Maybe, we can adapt the optimization idea but not about the exact types.
    CPython internally uses PyCMethod but expose it as PyCFunction. I think that will be very tricky in rust.

  9. youknowone commented on May 20, 2023

    @youknowone
    Member

    Partially resolved by #4873
    I decide not to strictly follow CPython implementation for this behavior. We expose BuiltinMethodType to user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-compatA discrepancy between RustPython and CPythonz-ca-2021Tag to track contrubution-academy 2021

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions