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
derived classes.
SpinaClass
is now a generic (SpinaClass<TBase>
), which takes in the
class being typed, merges with it, and sets the prototype to it. This
replaces theSpinaClass & TBase
we 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 toany
instead ofobject
, avoiding type
errors when looking for attributes/functions on parents.Backbone's
_Result<T>
is now exported in Spina asResult<T>
, giving
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
Result<T>
,
without having to suppress errors. Subclasses that define methods for
one or more dynamicResult<T>
attributes can now inherit from
DynamicAttrs(BaseClass, attr1, attr2, ...)
. At runtime, this is a
simple pass-through function that just returnsBaseClass
. 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.
Summary | ID |
---|---|
b2a852b0ae10943d5a4e20ab83243b94f80739e2 |
Description | From | Last Updated |
---|---|---|
2.1? |
david |