modular / modular/modular

[Feature Request] Re-enable `ConvertibleToPython` conformance for builtin types

Open
#6,546 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement mojo
Dominant language
Mojo
Stars
29.8k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

Review Mojo's priorities
What is your request?

Re-enabling ConvertibleToPython conformance for builtin types allows them to be used in generic code depending on ConvertibleToPython conformance.

What is your motivation for this change?

This was discussed on Discord with Chris and others.
https://discord.com/channels/1087530497313357884/1503501113217781810

It is appealing to me because it is cleaner and less arbitrary, but it does mix more python stuff into standard files. It is probably the cleanest solution though.
All this stuff will be much cleaner with extensions! 🙂
In any case, I support # 2 if you think this would help. Would you be willing to put up a PR?

Changes:

  • Remove implicit init methods on PythonObject for the builtin types (Bool, Int, Skalar, StringLiteral, StringSlice and String).
  • Add trait ConvertibleToPython to those types. This still allows for implicit conversion to PythonObject.
  • Add unit tests to check ConvertibleToPython conformance and implicit conversion
  • Aligns builtin types with custom types as both use the same implicit PythonObject init method.

As discussed with Chris I will open a PR for this change.

Any other details?

This is related to [mojo-stdlib] 3/x: Continue simplifying PythonObject implementation · modular/modular@5a23c2a where conformance to ConvertibleToPython was removed from builtin types to enable implicit conversion to PythonObject for custom types conforming to ConvertibleToPython.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the builtin type definitions for Bool, Int, Skalar, StringLiteral, StringSlice, and String, along with the PythonObject and ConvertibleToPython implementations. Review the related unit-test area before making changes. Done means the listed types conform to ConvertibleToPython, implicit PythonObject conversion remains covered, and the unit tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.