google / starlark-go

Starlark in Go: the Starlark configuration language, implemented in Go
BSD 3-Clause "New" or "Revised" License
2.26k stars 204 forks source link

Incomplete print() format, lack support of "%.02f" #493

Closed Turnkeys closed 11 months ago

Turnkeys commented 11 months ago

Python:

Python 3.11.3 (main, May  3 2023, 23:19:07) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print("%.02f" % (1/3))
0.33
>>> print("%f" % (1/3))
0.333333
>>>

Starlark:

Welcome to Starlark (go.starlark.net)
>>> print("%.02f" % (1/3))
Traceback (most recent call last):
  <stdin>:1:15: in <expr>
Error: unknown conversion %.
>>> print("%f" % (1/3))
0.333333
>>>
adonovan commented 11 months ago

I agree that this would be a good change, and that it was the original Starlark implementation shouldn't have skipped over this feature, though to be fair the need for precision control over numeric formatting rarely seems to arise in build system-like applications, and it can be safely added later.

But this change to the behavior of the % operator must be proposed to the Starlark spec first, not to any one of its implementations. Could you report this issue in the bazelbuild/starlark repo? Thanks.

Turnkeys commented 10 months ago

I agree that this would be a good change, and that it was the original Starlark implementation shouldn't have skipped over this feature, though to be fair the need for precision control over numeric formatting rarely seems to arise in build system-like applications, and it can be safely added later.

But this change to the behavior of the % operator must be proposed to the Starlark spec first, not to any one of its implementations. Could you report this issue in the bazelbuild/starlark repo? Thanks.

OK. Thanks! https://github.com/bazelbuild/starlark/issues/262