starlark icon indicating copy to clipboard operation
starlark copied to clipboard

RFE: document differences from Python

Open damienmg opened this issue 5 years ago • 3 comments

As reported by https://github.com/google/starlark-rust/issues/10, starlark does not support bool * string contrary to Python. There are two issues in the spec that led to that bug:

  • The specification contains some part concerning a type (in this case string) in generic sections (e.g. artihmetic operations) and the rest in a specific section (e.g. string. I would recommend to add cross-references in the string section pointing at all the section that one need to remember when implementing all the type. Or to simply repeat the generic sections in those.
  • The specifications does not contains any warning about difference with python (in this case, that the operation string * bool should not be supported).

damienmg avatar Sep 30 '18 20:09 damienmg

Well if it's intentional that this isn't supported than it certainly should be documented explicitly.

I'd argue against allowing bool * string. I believe it's only supported in Python as a consequence of implicit conversion of True -> 1 and False -> 0. In Python bool is a subtype of int, but I don't believe we have that concept in Starlark, except in the specific and explicit case that it's passed to the int() function.

brandjon avatar Oct 01 '18 12:10 brandjon

Agreed, this issue is for making the spec clearer about the fact that it is forbidden. Having bool not be a subtype of int would also be a good addendum.

damienmg avatar Oct 01 '18 13:10 damienmg

I don't think the spec should attempt to list all the differences from Python, though that does sound like a useful separate document in this repo. (The spec already notes that bool is not implicitly converted to int in arithmetic.)

alandonovan avatar Nov 13 '20 20:11 alandonovan