Skip to content

def has_array_namespace(obj) -> TypeIs[HasNamespace] #19

Description

@jorenham

I'm not sure if has_namespace is the best name for this typeguard, so Suggestions are welcome.

Example implementation that builds #17:

# _namespace.py
from typing_extensions import TypeIs

# --snip--

def has_namespace(obj: object, /) -> TypeIs[HasNamespace[Any]]:
    return hasattr(obj, "__array_namespace__")

Activity

  1. added theissue type on Jun 8, 2025
  2. changed the title [-]`def has_namespace(obj: ?, /) -> TypeIs[HasNamespace]`[/-] [+]`def has_namespace(obj) -> TypeIs[HasNamespace]`[/+] on Jun 8, 2025
  3. nstarman commented on Jun 8, 2025

    @nstarman
    Collaborator

    Given https://data-apis.org/array-api-compat/helper-functions.html#array_api_compat.array_namespace and that there's the linalg namespace, how about the more verbose has_array_namespace.

  4. changed the title [-]`def has_namespace(obj) -> TypeIs[HasNamespace]`[/-] [+]`def has_array_namespace(obj) -> TypeIs[HasNamespace]`[/+] on Jun 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✨ featureIntroduce new features.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions