From 4a38e3c804022fe81ed75714aff1ffe978e5d69f Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Thu, 9 Apr 2026 09:54:45 +0200 Subject: [PATCH 1/3] Added a .pyi stub file to type inspection with pylance --- pyproject.toml | 3 +++ src/cunumpy/__init__.pyi | 6 ++++++ src/cunumpy/py.typed | 0 tests/unit/test_app.py | 17 +++++++++++++++++ 4 files changed, 26 insertions(+) create mode 100644 src/cunumpy/__init__.pyi create mode 100644 src/cunumpy/py.typed diff --git a/pyproject.toml b/pyproject.toml index f86dae4..00f3c9c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,3 +48,6 @@ urls."Source" = "https://github.com/max-models/cunumpy" [tool.setuptools.packages.find] where = [ "src" ] + +[tool.setuptools.package-data] +cunumpy = [ "py.typed", "*.pyi" ] diff --git a/src/cunumpy/__init__.pyi b/src/cunumpy/__init__.pyi new file mode 100644 index 0000000..4c30806 --- /dev/null +++ b/src/cunumpy/__init__.pyi @@ -0,0 +1,6 @@ +# Stub file for Pylance/mypy: exposes all numpy symbols so that +# `import cunumpy as xp` followed by `xp.` shows numpy completions. +# At runtime the real __init__.py dispatches to numpy or cupy via __getattr__. +from numpy import * +from numpy import __version__, __config__ +from . import xp diff --git a/src/cunumpy/py.typed b/src/cunumpy/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/tests/unit/test_app.py b/tests/unit/test_app.py index ccb4e6d..ec2b129 100644 --- a/tests/unit/test_app.py +++ b/tests/unit/test_app.py @@ -1,3 +1,5 @@ +import numpy as np + import cunumpy as xp @@ -9,5 +11,20 @@ def test_xp_array(): print(f"{arr = } {type(arr) = }") +def test_numpy_symbols_accessible(): + """All public numpy symbols must be reachable via cunumpy. + + This validates the runtime behaviour that the stub file (__init__.pyi) + declares to Pylance so that `xp.` shows numpy completions in VS Code. + """ + missing = [ + name + for name in np.__all__ + if not hasattr(xp, name) + ] + assert missing == [], f"Symbols not accessible via cunumpy: {missing}" + + if __name__ == "__main__": test_xp_array() + test_numpy_symbols_accessible() From 0dc866cca3d77d5eac7c55fb4c4405f63161e53d Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Thu, 9 Apr 2026 10:06:31 +0200 Subject: [PATCH 2/3] Formatting --- src/cunumpy/__init__.pyi | 3 ++- tests/unit/test_app.py | 6 +----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/cunumpy/__init__.pyi b/src/cunumpy/__init__.pyi index 4c30806..b5fe885 100644 --- a/src/cunumpy/__init__.pyi +++ b/src/cunumpy/__init__.pyi @@ -2,5 +2,6 @@ # `import cunumpy as xp` followed by `xp.` shows numpy completions. # At runtime the real __init__.py dispatches to numpy or cupy via __getattr__. from numpy import * -from numpy import __version__, __config__ +from numpy import __config__, __version__ + from . import xp diff --git a/tests/unit/test_app.py b/tests/unit/test_app.py index ec2b129..ce6b9d0 100644 --- a/tests/unit/test_app.py +++ b/tests/unit/test_app.py @@ -17,11 +17,7 @@ def test_numpy_symbols_accessible(): This validates the runtime behaviour that the stub file (__init__.pyi) declares to Pylance so that `xp.` shows numpy completions in VS Code. """ - missing = [ - name - for name in np.__all__ - if not hasattr(xp, name) - ] + missing = [name for name in np.__all__ if not hasattr(xp, name)] assert missing == [], f"Symbols not accessible via cunumpy: {missing}" From 846b727fb8f59a4507362791fa12ab0347bd71a3 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Thu, 9 Apr 2026 10:07:04 +0200 Subject: [PATCH 3/3] Update version to 0.1.1 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 00f3c9c..c519bfd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ requires = [ "setuptools", "wheel" ] [project] name = "cunumpy" -version = "0.1" +version = "0.1.1" description = "Simple wrapper for numpy and cupy. Replace `import numpy as np` with `import cunumpy as xp`." readme = "README.md" keywords = [ "python" ]