Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overriding repr for custom types #535

Open
oprypin opened this issue Apr 2, 2024 · 1 comment
Open

Allow overriding repr for custom types #535

oprypin opened this issue Apr 2, 2024 · 1 comment

Comments

@oprypin
Copy link
Member

oprypin commented Apr 2, 2024

In Bazel's Starlark, the following holds:

  • str(Label('//:hi')) == '//:hi'
  • repr(Label('//:hi')) == 'Label("//:hi")'

However in starlark-go it is impossible to implement a Label object that would behave like this, instead the value of repr is forced to be '"//:hi"' per the straightforward implementation:

func repr(thread *Thread, _ *Builtin, args Tuple, kwargs []Tuple) (Value, error) {

Are there any plans to allow overriding repr of a particular type to be able to achieve this distinction?

@adonovan
Copy link
Collaborator

adonovan commented Apr 2, 2024

Are there any plans to allow overriding repr of a particular type to be able to achieve this distinction?

No, there are no plans. If this feature is really important it could be supported by defining a Reprable interface that the repr function would probe for, but our experience building a Bazel-like tool using starlark-go was that this wasn't necessary, even though it was technically a point of difference between the Go API and the java.starlark.net API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants