-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PEP 696 input type default #28
Comments
I think the way users will expect is something like this: ArrayT = OutputT = TypeVar('ArrayT', bound=Array)
InputT = TypeVar("InputT", default=float | ArrayT)
class Cosmology(Protocol[InputT, OutputT): ... Unfortunately, I think this will always require both type inputs since |
I'm not sure I follow. What we need to prescribe in the first instance is the array type that the cosmology instance works with: Then we have a situation where the input type can be array-like instead of being the exact array type. So we add a second type to the generic for that: Isn't that a good interface up to this point? The point of the issue is then merely that we could go one step further and leverage the PEP 696 semantics to give a sensible default value to We could also not do that at all, because defining cosmology protocol implementations is really only something that vendor libraries do, not users in their day to day work. |
My point is that the expectation is probably
But |
Yeah, I can see that if we phrased it in terms of input and output types, but I think in terms of array and array-like types it's fine. In any case I think we can separate this into three issues and discussions
What I meant to say above is that I think it would even be fine to support array-like input without PEP 696 (or other) default behaviour, because it's something that needs to be specified once per cosmology implementation. |
Thinking about this more, we could even target PEP 696 and define:
Cosmologies using numpy arrays could then accept
numpy.typing.ArrayLike
inputs, and e.g.cosmo.comoving_distance([z1, z2])
would remain legal, which is a big plus in my mind.Originally posted by @ntessore in #27 (comment)
The text was updated successfully, but these errors were encountered: