Skip to content

tensorflow: Add Tensor.__array__ method. #14342

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

Merged
merged 2 commits into from
Aug 8, 2025

Conversation

EthanAtLL
Copy link
Contributor

This PR adds the Tensor.__array__ method to support code like:

from typing import Protocol
import numpy as np
import tensorflow as tf

class ArrayLike(Protocol):
    def __array__(self) -> np.ndarray: ...
def convert(x: ArrayLike):
    return np.array(x)
def f(t: tf.Tensor):
    return convert(t) # originally errs with "__array__" is not present

This comment has been minimized.

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@EthanAtLL
Copy link
Contributor Author

Hi @srittau, Do you know what the next step to merging this would be?

Copy link
Contributor

github-actions bot commented Aug 8, 2025

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau srittau merged commit ba2e6b4 into python:main Aug 8, 2025
48 checks passed
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.

2 participants