The Python package is flat, like the crate root
Every public Python name is reached by one path, at the package root: geomcore.Circle, geomcore.BSplineSurface, geomcore.Point, geomcore.CurveCurveIntersection (issue #203). This is ADR 0022 for the bindings. Before this decision the shapes lived in geomcore.curves and geomcore.surfaces. Values, results, enums and errors were at the root, and the native module was reachable as geomcore.geomcore, a second path to every name that IDE completion offered next to the first. A user had to know which of three modules held a name, and the UX study's first script imported Plane from geomcore and failed.
- The extension module is
geomcore._native.geomcore/__init__.pyre-exports it, so the native module's name is private and no longer doubles every path. Every class's__module__isgeomcore, which is the path pickle records. Curve,Curve2DandSurfaceare public: each is the union of the classes of the Rust enum of the same name, and so their Python counterpart. In the stubs it is a type alias to annotate with. At runtime it is atyping.Unionof the same classes, whichisinstancetakes from Python 3.10. On 3.9,typing.get_args(Curve)gives the tuple.TrimmedCurveis not aCurve, as in Rust, where it is a piece of one and not an enum variant. A method that takes a whole curve or a piece is typedCurve | TrimmedCurve. One that takes or returns a whole curve only, such as a trimmed curve'sbasisor a swept surface's profile, saysCurve. The special case is spelled where it applies, rather than every whole-curve annotation needing a second, private name.geomcore.curvesandgeomcore.surfacesstay for one release as plain Python modules. Each name they held resolves through a module__getattr__with aDeprecationWarning, so code and pickles written against them keep working.- The stubs are one file,
geomcore/__init__.pyi.curves.pyiandsurfaces.pyionly re-export, for type checkers reading the deprecated imports.
The root holds about 90 names. Like the crate root's 150 (ADR 0022), they do not collide, and a name says its kind (…Intersection, …Error, the 2D suffix of ADR 0013).
Considered options
- Keep the split and document a module map: rejected. Three modules to learn, against one in Rust, and the shapes were the only names a user had to look up.
- Re-export the shapes at the root and keep the submodules for good: rejected. Two paths per shape, the doubling ADR 0022 removed from Rust.
- Runtime
Curveas a tuple of classes: rejected. It works withisinstanceon every version, but stubtest and mypy see a tuple where the stub has a union, so the one name could not serve both uses. CurveincludingTrimmedCurve, with a private_WholeCurvefor the rest: rejected. It made every whole-curve annotation (a trimmed curve's basis, a swept profile, the result ofuv_curve_to_3d) use a private name in the public stubs, and the PythonCurvediffered from the Rust enum.- An abstract base class registering each class: rejected. The stub classes would have to inherit it, and its methods would be typed twice, as the sets already are (ADR 0029).
Consequences
- Breaking in the next release:
geomcore.curvesandgeomcore.surfacesare removed, andgeomcore.geomcoreis gone now. It was never documented. isinstance(x, geomcore.Curve)raises on Python 3.9.typing.get_argsis the portable form.
Amended (#295): geomcore.curves and geomcore.surfaces stayed through 0.47 rather than one release, and are removed in 0.48. The stubs hold one __all__, and the parity test reads __init__.pyi alone.