Skip to content

Some failures in whats_left.sh: method inheritance not as expected #2732

Closed

Description

@jamestwebber

Feature

The whats_left.sh script generates a list of incompatibilities by comparing signatures with inspect.signature(). I think one source of mismatches is because of how builtin object inherit (or don't inherit) from object. I don't yet understand how RustPython is doing this so I'm documenting the issue here, but I could write a PR with some help.

Description

As an example: sys.__loader__ is listed by whats_left because signature() returns a ValueError. The CPython signature is (), which is the default signature of object.

In both CPython and RustPython inspect.signature is calling inspect._signature_from_callable() (code), which eventually gets to this block.

The class is an instance of _frozen_importlib.BuiltinImporter which has no __init__ or __new__ method defined. In CPython, both of those methods are the same as the object methods (using the is test, e.g. the same memory address). In RustPython the __new__ method is different. I would guess that something about the class definition is creating a separate __new__ method even though there shouldn't be one.

Activity

  1. youknowone commented on Aug 4, 2021

    @youknowone
    Member

    @jamestwebber is this fixed by your PRs?

  2. jamestwebber commented on Aug 4, 2021

    @jamestwebber
    ContributorAuthor

    Unfortunately no, I just collapse the error into a single message.

    In the case of __loader__ the same message showed up many times because every built-in module had a __loader__ instance that came from _frozen_importlib. So my PRs turn that into one message but the underlying cause is still there.

  3. moreal commented on Aug 14, 2021

    @moreal
    Contributor

    I resolved #2869 so I believe this issue is also resolved as I understood. To prove this issue is resolved, I executed ./whats_left.sh and looked up sys.__loader__ but I couldn't. But I can't feel sure that this issue was resolved, could you check it? @jamestwebber

  4. jamestwebber commented on Aug 14, 2021

    @jamestwebber
    ContributorAuthor

    Yes, this is fixed! The messages were no longer output by whats_left because in #2760 I tweaked the code to remove items defined in other modules (in retrospect perhaps this was too broad, as there are no examples of __loader__ left to check). But I verified the change in behavior which fixes this issue:

    >>>>> import sys
    >>>>> sys.__loader__.__init__ is object.__init__
    True
    >>>>> sys.__loader__.__new__ is object.__new__
    True  # was previously False

    This has uncovered a new issue: in CPython, inspect.signature(object) will return () but RustPython raises a ValueError. I think this is a different problem though.

  5. jamestwebber commented on Aug 14, 2021

    @jamestwebber
    ContributorAuthor

    Oh, the underlying issue is now #2410 which you're already working on 🎉

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions