Skip to content

fix(python_api): correct hasattr call for __array_interface__ check#14458

Closed
Hrk84ya wants to merge 2 commits intopytest-dev:mainfrom
Hrk84ya:main
Closed

fix(python_api): correct hasattr call for __array_interface__ check#14458
Hrk84ya wants to merge 2 commits intopytest-dev:mainfrom
Hrk84ya:main

Conversation

@Hrk84ya
Copy link
Copy Markdown

@Hrk84ya Hrk84ya commented May 10, 2026

  • Fix typo in hasattr call: change hasattr("obj", ...) to hasattr(obj, ...)
  • Ensures array_interface attribute is checked on the actual object instead of the string literal "obj"
  • Prevents incorrect behavior when converting objects to numpy arrays

Hrk84ya and others added 2 commits May 10, 2026 12:08
- Fix typo in hasattr call: change hasattr("obj", ...) to hasattr(obj, ...)
- Ensures __array_interface__ attribute is checked on the actual object instead of the string literal "obj"
- Prevents incorrect behavior when converting objects to numpy arrays
Copilot AI review requested due to automatic review settings May 10, 2026 06:46
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a bug in pytest’s internal NumPy interoperability used by pytest.approx, ensuring array-like objects are detected correctly when they implement NumPy’s legacy __array_interface__ protocol.

Changes:

  • Corrects the hasattr call to check __array_interface__ on the actual input object rather than the string literal "obj".

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/_pytest/python_api.py
Comment on lines +909 to 910
elif hasattr(obj, "__array__") or hasattr(obj, "__array_interface__"):
return np.asarray(obj)
@Hrk84ya Hrk84ya closed this May 10, 2026
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