Skip to content

TYP: Add annotations for the py3.12 buffer protocol - #24705

Merged
charris merged 3 commits into
numpy:mainfrom
BvB93:buffer
Sep 14, 2023
Merged

charris merged 3 commits into
numpy:mainfrom
BvB93:buffer

Conversation

@BvB93

@BvB93 BvB93 commented Sep 14, 2023

Copy link
Copy Markdown
Member

With the implementation of PEP 688 the buffer protocol is, as of Python 3.12, now accessible in Python. This PR updates the np.ndarray and np.generic annotations, adding the corresponding __buffer__ method to the both of them in addition to the definition of npt.ArrayLike.

Marking as 1.26 backport as this is a reasonably py3.12 typing feature.

@charris

charris commented Sep 14, 2023

Copy link
Copy Markdown
Member

@BvB93 I have an unrelated question.

charris@fc [numpy.git (prepare-1.26.0-release)]$ git diff main numpy/f2py
diff --git a/numpy/f2py/__init__.pyi b/numpy/f2py/__init__.pyi
index 81b6a24f39..6e3a82cf8f 100644
--- a/numpy/f2py/__init__.pyi
+++ b/numpy/f2py/__init__.pyi
@@ -14,6 +14,7 @@ class _F2PyDict(_F2PyDictBase, total=False):
     ltx: list[str]
 
 __all__: list[str]
+__path__: list[str]
 test: PytestTester

I assume the difference is harmless. Is it?

@BvB93

BvB93 commented Sep 14, 2023

Copy link
Copy Markdown
Member Author

I assume the difference is harmless. Is it?

Correct, it's harmless. I would recommend leaving __path__ out if it's not too much work (it's an attribute that's explicitly handled by type checkers these days), but either way is fine tbh.

@charris

charris commented Sep 14, 2023

Copy link
Copy Markdown
Member

The test failures look unrelated. The macos_arm64_test crash is new. Hmm ... Will rerun.

@charris
charris merged commit f6bf183 into numpy:main Sep 14, 2023
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Sep 14, 2023
@charris

charris commented Sep 14, 2023

Copy link
Copy Markdown
Member

Thanks Bas.

@seiko2plus Any chance the aarch64 fixes could have accounted for the macos_arm64_test crash? I'm sorry that I reran the test, but wanted to see if it was repeatable.

@BvB93
BvB93 deleted the buffer branch September 14, 2023 16:33
@seiko2plus

Copy link
Copy Markdown
Member

Any chance the aarch64 fixes could have accounted for the macos_arm64_test crash?

I ran tests on clang 14 & 15, both were fine. If the partial load refactor (gh-24461) is the issue, then it should be consistent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants