You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
gh-37613: Fix hyperelliptic curve dynamic class construction to allow proper method inheritance
While working on some hyperelliptic code, I realised the dynamic class
construction had an issue with inheritance for the genus two classes and
certain methods which should have been available were not.
This is discussed in more detail in the issue
#37612
I do not know a *good* fix for this, but I have found a fix which at
least allows the functions supposed to be accessed to be accessed.
I have added a small doctest to ensure that the method called for genus
two curves is bound to the correct class.
## Overview of the fix
The original class was constructed as:
```py
cls = dynamic_class(class_name,
tuple(superclass),
cls=HyperellipticCurve_generic,
doccls=HyperellipticCurve)
```
Where `superclass` is either an empty list, a list with a single child
from:
- `HyperellipticCurve_finite_field`
- `HyperellipticCurve_rational_field`
- `HyperellipticCurve_padic_field`
- `HyperellipticCurve_g2`
Notice that all four of these classes are children of
`HyperellipticCurve_generic`.
Or, in the case of the base field being one of the above AND the curve
being genus two this list is of the form:
```
[HyperellipticCurve_XXX_field, HyperellipticCurve_g2]
```
In this case, I found that the dynamic class insertion into `cls` meant
that the methods shared by one of the "`superclass`" (probably should be
called base classes?) and `cls` itself would call the method from `cls`
rather than the superclass and so all specialised functions were
unavailable, making the genus two optimisations redundant.
In my new fix, if `superclass` has a length of zero, I set `cls` to be
`HyperellipticCurve_generic`, otherwise `cls` is `None`.
This seems to work, but I don't know if this is good practice.
Fixes#37612
URL: #37613
Reported by: Giacomo Pope
Reviewer(s): Giacomo Pope, Kwankyu Lee
0 commit comments