Closed gabbard closed 5 years ago
Comment by ConstantineLignos
Tuesday Nov 28, 2017 at 15:12 GMT
@rgabbard Can you take a stab at this? I'm imagining an additional argument to the immutable collection of
methods that specify whether to check isinstance
of each thing in the collection and raise a TypeError
if it doesn't match. Then update attrutils
attrib_{opt}_immutable
.
It's probably easiest if you branch off of immutable-document
to something like immutable-document-features
to add this and whatever other things you add.
Comment by ConstantineLignos
Tuesday Nov 28, 2017 at 16:00 GMT
While you're touching immutable collections, see if you can clean up this idiom:
self._regions_to_include: ImmutableSet[str] = (ImmutableSet.of(regions_to_include)
if regions_to_include is not None
else ImmutableSet.empty())
attrib_opt_immutable
may already have the solution, I can't remember how that works.
Comment by rgabbard
Wednesday Nov 29, 2017 at 23:29 GMT
@ConstantineLignos : the second case can be slightly improved (?) to
self._regions_to_include: ImmutableSet[str] = (ImmutableSet.of(regions_to_include or ImmutableSet.empty()))
Which is still awkward. If performance isn't super-important, ImmutableSet.of(regions_to_include or [])
is not bad.
Comment by rgabbard
Wednesday Nov 29, 2017 at 23:31 GMT
Ah, wait, does ImmutableSet.empty()
magically evaluate to false like a regular empty collection?
Comment by ConstantineLignos
Wednesday Nov 29, 2017 at 23:33 GMT
I haven't tested but I'm pretty sure AbstractSet[T]
will take care of that.
Comment by rgabbard
Friday Dec 08, 2017 at 15:21 GMT
This is done for ImmutableSet
(optionally, should it be on by default?) but not ImmutableList
, ImmutableDict
, or ImmutableMultiDict
I believe we have determine that the performance cost of this is significant enough we do not want to pursue it as part of this library.
In the new data model, we'd like to have type checking of theory items that contain (refer to) other theory items, e.g.
Old model:
New model:
No error here.
In general, we want (runtime) type checking on all immutablecollections.