starlark
starlark copied to clipboard
RFE: document differences from Python
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).
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.
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.
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.)