Skip to content

Add NativeScope for single-base native types - #239

Open
MridulS wants to merge 1 commit into
scipp:mainfrom
MridulS:nanobind-native-scope-prototype
Open

Add NativeScope for single-base native types#239
MridulS wants to merge 1 commit into
scipp:mainfrom
MridulS:nanobind-native-scope-prototype

Conversation

@MridulS

@MridulS MridulS commented Aug 25, 2026

Copy link
Copy Markdown
Member

Provide a runtime-erased NativeScope base and native_scope decorator for generic identity keys around extension types that cannot support multiple inheritance. Preserve Scope-compatible specialization and add API coverage.

Provide a runtime-erased NativeScope base and native_scope decorator for
generic identity keys around extension types that cannot support multiple
inheritance. Preserve Scope-compatible specialization and add API coverage.
@MridulS
MridulS requested a review from jl-wynen August 25, 2026 08:46
@SimonHeybrock

Copy link
Copy Markdown
Member

Is this still necessary if we properly support 3.12 generics, see #237?

@MridulS

MridulS commented Aug 25, 2026

Copy link
Copy Markdown
Member Author

Actually no PEP 695 isn't enough here, as it adds typing.Generic as a base class so we end up with multiple inheritance anyway.

>>> class Test:
...     pass
...
>>> class Apple[A](Test):
...     pass
...
>>> Apple.__bases__
(<class '__main__.Test'>, <class 'typing.Generic'>)

@SimonHeybrock

Copy link
Copy Markdown
Member

In other words: Switching scipp to nanobind would make scipp incompatible with PEP 695 generics?

@MridulS

MridulS commented Aug 25, 2026

Copy link
Copy Markdown
Member Author

Yeahh, but only if we are doing subclassing with the generics like class Data[T](sc.DataArray). Where else are we using this pattern?

A function like def func[T](data: sc.DataArray) is just fine.

@SimonHeybrock

Copy link
Copy Markdown
Member

Yeahh, but only if we are doing subclassing with the generics like class Data[T](sc.DataArray).

My plan (from close to the time of first Sciline implementation) had been to remove all our use of the Scope (which we mostly considered a workaround) when we have PEP 695 generics. So the answer is kind of "everywhere".

@jl-wynen

Copy link
Copy Markdown
Member

What about generic aliases like

type Data[T] = sc.DataArray

?

@MridulS

MridulS commented Aug 26, 2026

Copy link
Copy Markdown
Member Author

type Data[T] = sc.DataArray works just fine, as there is no subclassing happening.

@SimonHeybrock

Copy link
Copy Markdown
Member

type Data[T] = sc.DataArray works just fine, as there is no subclassing happening.

That sounds like a reasonable alternative then -- we do not actually want to subclass Scipp types.

@MridulS

MridulS commented Aug 26, 2026

Copy link
Copy Markdown
Member Author

How do you want to proceed here then? Should we try to get #237 merged or test out the nanobind version with this PR first? I would prefer minimal and revertable changes first to make sure the nanobinded scipp works out of the box across the stack. I checked easy* code too and couldn't find a place where they do any multi inhertiance and neither in https://github.com/kinisi-dev/kinisi (@jl-wynen mentioned that it's built on top of scipp)

@jl-wynen

Copy link
Copy Markdown
Member

I would prefer to update sciline and the ess packages first. Then we can test the nanobind update with the whole stack again.

@MridulS

MridulS commented Aug 27, 2026

Copy link
Copy Markdown
Member Author

I would prefer to update sciline and the ess packages first

Yes but with this PR or #237?

@jl-wynen

Copy link
Copy Markdown
Member

Some variant of #237
I think this PR won't be needed if / when we support the new type aliases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants