Skip to content

Does standard prohibit inclusion of additional keyword-only arguments? #869

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

Closed
mdhaber opened this issue Dec 7, 2024 · 5 comments · Fixed by #870
Closed

Does standard prohibit inclusion of additional keyword-only arguments? #869

mdhaber opened this issue Dec 7, 2024 · 5 comments · Fixed by #870
Labels
Narrative Content Narrative documentation content.
Milestone

Comments

@mdhaber
Copy link
Contributor

mdhaber commented Dec 7, 2024

The "Conformance" section states:

A conforming implementation of the array API standard must provide and support all the functions, arguments, data types, syntax, and semantics described in this specification.

A conforming implementation of the array API standard may provide additional values, objects, properties, data types, and functions beyond those described in this specification.

This seems to leave a bit of gray area. For instance, can implementations of functions defined in the standard accept additional arguments not defined by the standard (as long as the default behavior complies with the standard)?

Let's take numpy.asarray as an example implementation of asarray.

I know that the fact that the positional arguments are not positional-only is non-conformant: "When a function signature includes a /, positional parameters must be positional-only parameters." Likewise, dtype should be keyword only. That aside....

Is NumPy's inclusion of an additional positional argument order considered non-conformant? How about the keyword-only argument like?

@rgommers
Copy link
Member

rgommers commented Dec 7, 2024

Extra optional positional arguments and keywords can always be added by an implementation, that is perfectly fine and every existing implementation except for array-api-strict does that. If the text needs to be clearer, let's amend it. I think you want to add "and function arguments" to the quoted list above?

Is NumPy's inclusion of an additional positional argument order considered non-conformant? How about the keyword-only argument like?

So those are both fine.

@mdhaber
Copy link
Contributor Author

mdhaber commented Dec 7, 2024

I think you want to add "and function arguments" to the quoted list above?

Yup! I will submit a PR to add exactly that.

This came up in mdhaber/marray#6 (comment).

@mdhaber
Copy link
Contributor Author

mdhaber commented Dec 7, 2024

Would this be ok to make it explicit that the list is not comprehensive?

A conforming implementation of the array API standard may provide additional
features (e.g. values, objects, properties, data types, functions, and function
arguments) beyond those described in this specification.

Or is that too flexible?

@rgommers
Copy link
Member

rgommers commented Dec 7, 2024

That sounds perfectly fine to me.

@asmeurer
Copy link
Member

asmeurer commented Dec 7, 2024

Code written against the strictest implementations of the standard should work. That means that additional optional keyword arguments are fine, because even though most code won't reference them, they will have default values. But additional required positional or keyword arguments are not OK, because those will require the code to be updated. So for example, if the standard defines

def f(x, /, y=1):
    ...

an implementation could define

def f(x, /, y=1, z=2):
    ...

but it would not be OK for an implementation to define

def f(x, z, /, y=1):
    ...

or

def f(x, /, *, z, y=1):
    ...

because code written against the standard like f(x) or f(x, y=2) would give errors for those implementations.

@kgryte kgryte added the Narrative Content Narrative documentation content. label Dec 11, 2024
@kgryte kgryte added this to the v2024 milestone Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Narrative Content Narrative documentation content.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants