Enhance Spina class typing and dynamic attribute method support.
Review Request #13222 — Created Aug. 17, 2023 and discarded
This change improves typing support throughout Spina, helping to cement
some patterns, improve code maintenance, and correct typing issues in
SpinaClassis now a generic (
SpinaClass<TBase>), which takes in the
class being typed, merges with it, and sets the prototype to it. This
SpinaClass & TBasewe had internally in several places,
and gives us a proper up-front type to avoid some casting. Untyped, it
behaves like it did before.
__super__is now mapped to
object, avoiding type
errors when looking for attributes/functions on parents.
_Result<T>is now exported in Spina as
us a non-private, stable type we can use when we need to reference a
type or callable returning the type.
And then, finally, we have a fix for defining methods for
without having to suppress errors. Subclasses that define methods for
one or more dynamic
Result<T>attributes can now inherit from
DynamicAttrs(BaseClass, attr1, attr2, ...). At runtime, this is a
simple pass-through function that just returns
BaseClass. During type
checking, it carefully omits the provided attributes from the parent and
allows the child to define them as methods, which will then be seen in
that class's typing.
This helps avoid all sorts of issues. By default, these attributes are
seen as non-methods, and must be treated as such. But when using
DynamicAttrs, they're seen as methods explicitly, and
subclasses/callers must treat them as such.
Unit tests pass.
Tested this with some in-progress work.