python-variants/variants

Be lazier about variants in methods

Opened this issue · 1 comments

The way this works now, the VariantFunction descriptor will create a new VariantMethod at least for every instance of the parent class, possibly on every lookup of either the primary or one of the variants. This is particularly problematic because instantiating a VariantMethod actually eagerly binds every variant at lookup time.

I believe that we can fix this by changing VariantMethod so that rather than eagerly creating bound method variants for every variant of the primary when instantiated, we have a lookup table that lazily creates them in __getattr__.

The big caveat here is that if you just do it the naive way, I'm fairly certain that it will ruin introspection and (probably ruin documentation generation as a consequence), so I think we'll also have to be clever about the introspection.

I think this can be postponed to the first feature release, since variants works already.