Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,36 @@ jobs:
matrix:
config:
[
{
pybind11-branch: "v3.0",
python: "3.13",
numpy-format: "numpy-array-use-type-var",
cmake-version: "4.2.x",
},
{
pybind11-branch: "v3.0",
python: "3.13",
numpy-format: "numpy-array-wrap-with-annotated",
cmake-version: "4.2.x",
},
{
pybind11-branch: "v3.0",
python: "3.12",
numpy-format: "numpy-array-wrap-with-annotated",
cmake-version: "4.2.x",
},
{
pybind11-branch: "v3.0",
python: "3.11",
numpy-format: "numpy-array-wrap-with-annotated",
cmake-version: "4.2.x",
},
{
pybind11-branch: "v3.0",
python: "3.10",
numpy-format: "numpy-array-wrap-with-annotated",
cmake-version: "4.2.x",
},
{
pybind11-branch: "v2.13",
python: "3.13",
Expand Down Expand Up @@ -166,7 +196,7 @@ jobs:

- name: Check error generation
shell: bash
run: ./tests/check-demo-errors-generation.sh
run: ./tests/check-demo-errors-generation.sh "pybind11-${{ matrix.config.pybind11-branch }}"

test-cli-options:
name: "Runs on 🐍 ${{ matrix.python }} • ${{ matrix.test-package }}"
Expand Down
10 changes: 8 additions & 2 deletions tests/check-demo-errors-generation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

set -e

if [ "$#" -lt 1 ]; then
echo "Usage: $0 pybind11-vX.Y [path]"
exit 1
fi

resolve_path() {
local path="$1"
local path="$2"

while [ -L "$path" ]; do
path="$(readlink "$path")"
Expand All @@ -17,7 +22,8 @@ resolve_path() {
}

TESTS_ROOT="$(resolve_path "$(dirname "$0")")"
DEMO_ERRORS_FILE="${TESTS_ROOT}/demo.errors.stderr.txt"
ERRORS_ROOT="$(resolve_path "${TESTS_ROOT}/errors/$1")"
DEMO_ERRORS_FILE="${ERRORS_ROOT}/demo.errors.stderr.txt"
STUBS_DIR="/tmp/out" # Stubs should never be actually written

remove_demo_errors() {
Expand Down
1 change: 1 addition & 0 deletions tests/errors/pybind11-v2.11
1 change: 1 addition & 0 deletions tests/errors/pybind11-v2.12
1 change: 1 addition & 0 deletions tests/errors/pybind11-v2.13
15 changes: 15 additions & 0 deletions tests/errors/pybind11-v3.0/demo.errors.stderr.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pybind11_stubgen - [ ERROR] In demo._bindings.aliases.foreign_enum_default : Invalid expression '<ConsoleForegroundColor.Blue: 34>'
pybind11_stubgen - [ ERROR] In demo._bindings.enum.accept_defaulted_enum : Invalid expression '<ConsoleForegroundColor.None_: -1>'
pybind11_stubgen - [ ERROR] In demo._bindings.flawed_bindings.accept_unbound_enum : Invalid expression '(anonymous namespace)::Enum'
pybind11_stubgen - [ ERROR] In demo._bindings.flawed_bindings.accept_unbound_enum_defaulted : Invalid expression '<demo._bindings.flawed_bindings.Enum object at 0x1234abcd5678>'
pybind11_stubgen - [ ERROR] In demo._bindings.flawed_bindings.accept_unbound_type : Invalid expression '(anonymous namespace)::Unbound'
pybind11_stubgen - [ ERROR] In demo._bindings.flawed_bindings.accept_unbound_type_defaulted : Invalid expression '<demo._bindings.flawed_bindings.Unbound object at 0x1234abcd5678>'
pybind11_stubgen - [ ERROR] In demo._bindings.flawed_bindings.get_unbound_type : Invalid expression '(anonymous namespace)::Unbound'
pybind11_stubgen - [WARNING] Enum-like str representations were found with no matching mapping to the enum class location.
Use `--enum-class-locations` to specify full path to the following enum(s):
- ConsoleForegroundColor
pybind11_stubgen - [WARNING] Raw C++ types/values were found in signatures extracted from docstrings.
Please check the corresponding sections of pybind11 documentation to avoid common mistakes in binding code:
- https://pybind11.readthedocs.io/en/latest/advanced/misc.html#avoiding-cpp-types-in-docstrings
- https://pybind11.readthedocs.io/en/latest/advanced/functions.html#default-arguments-revisited
pybind11_stubgen - [ INFO] Terminating due to previous errors
1 change: 0 additions & 1 deletion tests/stubs/python-3.11

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from __future__ import annotations

from demo._bindings import (
aliases,
classes,
eigen,
enum,
flawed_bindings,
functions,
issues,
methods,
numpy,
properties,
stl,
stl_bind,
typing,
values,
)

from . import _bindings, core, pure_python

__all__: list[str] = [
"aliases",
"classes",
"core",
"eigen",
"enum",
"flawed_bindings",
"functions",
"issues",
"methods",
"numpy",
"properties",
"pure_python",
"stl",
"stl_bind",
"typing",
"values",
"version",
]
version: str = "0.0.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from __future__ import annotations

from . import (
aliases,
classes,
eigen,
enum,
flawed_bindings,
functions,
issues,
methods,
numpy,
properties,
stl,
stl_bind,
typing,
values,
)

__all__: list[str] = [
"aliases",
"classes",
"eigen",
"enum",
"flawed_bindings",
"functions",
"issues",
"methods",
"numpy",
"properties",
"stl",
"stl_bind",
"typing",
"values",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from __future__ import annotations

import typing

import numpy
from numpy import random

import demo._bindings.enum
from demo._bindings.aliases.foreign_method_arg import Bar2 as foreign_type_alias
from demo._bindings.aliases.foreign_return import get_foo as foreign_class_alias

from . import (
foreign_arg,
foreign_attr,
foreign_class_member,
foreign_method_arg,
foreign_method_return,
foreign_return,
missing_self_arg,
)

__all__: list[str] = [
"Color",
"Dummy",
"foreign_arg",
"foreign_attr",
"foreign_class_alias",
"foreign_class_member",
"foreign_enum_default",
"foreign_method_arg",
"foreign_method_return",
"foreign_return",
"foreign_type_alias",
"func",
"local_func_alias",
"local_type_alias",
"missing_self_arg",
"random",
]

class Color:
pass

class Dummy:
linalg = numpy.linalg

def foreign_enum_default(
color: typing.Any = demo._bindings.enum.ConsoleForegroundColor.Blue,
) -> None: ...
def func(arg0: int) -> int: ...

local_func_alias = func
local_type_alias = Color
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from __future__ import annotations

import demo._bindings.classes

__all__: list[str] = ["set_foo"]

def set_foo(arg0: demo._bindings.classes.Foo) -> int: ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from __future__ import annotations

import demo._bindings.classes

__all__: list[str] = ["value"]
value: demo._bindings.classes.Foo # value = <demo._bindings.classes.Foo object>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from __future__ import annotations

import typing

import demo._bindings.classes

__all__: list[str] = ["Bar1"]

class Bar1:
foo: typing.ClassVar[
demo._bindings.classes.Foo
] # value = <demo._bindings.classes.Foo object>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from __future__ import annotations

import demo._bindings.classes

__all__: list[str] = ["Bar2"]

class Bar2:
def set_foo(self, arg0: demo._bindings.classes.Foo) -> int: ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from __future__ import annotations

import demo._bindings.classes

__all__: list[str] = ["Bar3"]

class Bar3:
@staticmethod
def get_foo() -> demo._bindings.classes.Foo: ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from __future__ import annotations

import demo._bindings.classes

__all__: list[str] = ["get_foo"]

def get_foo() -> demo._bindings.classes.Foo: ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from __future__ import annotations

import demo._bindings.classes

__all__: list[str] = ["Bar4"]

class Bar4:
def set_foo(self: demo._bindings.classes.Foo) -> int: ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from __future__ import annotations

import typing

__all__: list[str] = ["Base", "CppException", "Derived", "Foo", "Outer"]

class Base:
class Inner:
pass

name: str

class CppException(Exception):
pass

class Derived(Base):
count: int

class Foo:
class FooChild:
def __init__(self) -> None: ...
def g(self) -> None: ...

def __init__(self) -> None: ...
def f(self) -> None: ...

class Outer:
class Inner:
class NestedEnum:
"""
Members:

ONE

TWO
"""

ONE: typing.ClassVar[Outer.Inner.NestedEnum] # value = <NestedEnum.ONE: 1>
TWO: typing.ClassVar[Outer.Inner.NestedEnum] # value = <NestedEnum.TWO: 2>
__members__: typing.ClassVar[
dict[str, Outer.Inner.NestedEnum]
] # value = {'ONE': <NestedEnum.ONE: 1>, 'TWO': <NestedEnum.TWO: 2>}
def __eq__(self, other: typing.Any) -> bool: ...
def __getstate__(self) -> int: ...
def __hash__(self) -> int: ...
def __index__(self) -> int: ...
def __init__(self, value: int) -> None: ...
def __int__(self) -> int: ...
def __ne__(self, other: typing.Any) -> bool: ...
def __repr__(self) -> str: ...
def __setstate__(self, state: int) -> None: ...
def __str__(self) -> str: ...
@property
def name(self) -> str: ...
@property
def value(self) -> int: ...

value: Outer.Inner.NestedEnum

inner: Outer.Inner
Loading