Overall, struct reminds me Python's namedtuple and its behavior in such case seems more appropriate:
>>> import collections
>>> collections.namedtuple('Foo', ['foo.bar'])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/collections.py", line 351, in namedtuple
'alphanumeric characters and underscores: %r' % name)
ValueError: Type names and field names can only contain alphanumeric characters and underscores: 'foo.bar'
or in Python 3
>>> import collections
>>> collections.namedtuple('Foo', ['foo.bar'])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/collections/__init__.py", line 361, in namedtuple
raise ValueError('Type names and field names must be valid '
ValueError: Type names and field names must be valid identifiers: 'foo.bar'
The only reason I can think of for allowing arbitrary keys is to allow users serialize their dictionaries into json, since struct.to_json is the only way to serialize data structures exposed to users. In such case would it make sense to just have a separate native function to_json that supports all supported data structures and stop accepting dots and possibly other types of keys like keywords (https://github.com/python/cpython/blob/master/Lib/collections/__init__.py#L357-L365)?
--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/7626bc49-7796-48b4-b002-2f85009d12af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
load("//__native:modules.bzl", "json")json.to_json(...)