Skip to content

Add type hints / annotations to array_namespace(): array_api_strict as return type? #194

Closed as not planned

Description

@34j

Without type hints, it is very inconvenient because of spelling errors of array_api functions. As array_api_compat seems to be a superset of array_api_strict, I would like to propose to simply set the return type of array_namespace() to array_api_strict, although it might be confusing.

def array_namespace(*xs, api_version=None, use_compat=None):

from typing import overload
import array_api_strict

array_api_compat_type = array_api_strict

@overload
def array_namespace(*xs, api_version=None, use_compat: None=None) -> array_api_compat_type:
	...

Activity

  1. asmeurer commented on Nov 6, 2024

    @asmeurer
    Member

    I think upstream work to make a protocol out of the array API namespace would be what we'd want here.

    data-apis/array-api#685
    data-apis/array-api#267

    Setting the return type as array_api_strict seems wrong. array_api_strict isn't a type, it's a module, and it isn't even the module that's returned in most cases. The correct return type would be typing.ModuleType, which we can definitely add, although I don't think that alone would make it infer much.

  2. lucascolley commented on Jan 26, 2025

    @lucascolley
    Member

    let's close this one - we would of course like to annotate all of array-api-compat once the necessary tools are available in array-api-typing.

  3. 34j commented on Jun 5, 2025

    @34j
    Author

    I just want to make sure that, once array-api-typing is complete, get_namespace() will return ArrayNamespace or something, is that right? I hope you could leave this issue open as development of array-api-typing is resumed. (Not sure why you have closed this. I understand that you want to reduce the number of open Issues though.)

  4. lucascolley commented on Jun 5, 2025

    @lucascolley
    Member

    once array-api-typing is complete, get_namespace() will return ArrayNamespace or something, is that right?

    That sounds right 👍

    (Not sure why you have closed this. I understand that you want to reduce the number of open Issues though.)

    Yes, sorry, in case it wasn't clear, my rationale for closing was that:

    • this is not actionable right now
    • this doesn't track something that we might 'forget' about later. In other words, once the work in array-api-typing is done, addressing this issue will be an obvious next step.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions