diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4778517..b2418d5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -97,8 +97,8 @@ jobs: uses: actions/upload-artifact@v3 if: failure() with: - name: "python-${{ matrix.python }}-pybind-${{ matrix.pybind11-branch }}.patch" - path: "./tests/stubs/python-${{ matrix.python }}/pybind11-${{ matrix.pybind11-branch }}.patch" + name: "python-${{ matrix.python }}-pybind-${{ matrix.pybind11-branch }}-${{ matrix.numpy-format }}.patch" + path: "./tests/stubs/python-${{ matrix.python }}/pybind11-${{ matrix.pybind11-branch }}/${{ matrix.numpy-format }}.patch" retention-days: 30 if-no-files-found: ignore diff --git a/pybind11_stubgen/__init__.py b/pybind11_stubgen/__init__.py index 2de7f21..8cfb9aa 100644 --- a/pybind11_stubgen/__init__.py +++ b/pybind11_stubgen/__init__.py @@ -48,6 +48,7 @@ RemoveSelfAnnotation, ReplaceReadWritePropertyWithField, RewritePybind11EnumValueRepr, + WrapInvalidExpressions, ) from pybind11_stubgen.parser.mixins.parse import ( BaseParser, @@ -276,6 +277,7 @@ class Parser( FixRedundantMethodsFromBuiltinObject, RemoveSelfAnnotation, FixPybind11EnumStrDoc, + WrapInvalidExpressions, ExtractSignaturesFromPybind11Docstrings, ParserDispatchMixin, BaseParser, @@ -306,7 +308,7 @@ def main(): args = arg_parser().parse_args(namespace=CLIArgs()) parser = stub_parser_from_args(args) - printer = Printer(invalid_expr_as_ellipses=not args.print_invalid_expressions_as_is) + printer = Printer() out_dir, sub_dir = to_output_and_subdir( output_dir=args.output_dir, diff --git a/pybind11_stubgen/parser/mixins/fix.py b/pybind11_stubgen/parser/mixins/fix.py index 4360dab..4d7756f 100644 --- a/pybind11_stubgen/parser/mixins/fix.py +++ b/pybind11_stubgen/parser/mixins/fix.py @@ -144,6 +144,11 @@ def handle_value(self, value: Any) -> Value: result = super().handle_value(value) if inspect.isroutine(value) and result.is_print_safe: self._add_import(QualifiedName.from_str(result.repr)) + else: + type_ = type(value) + self._add_import( + QualifiedName.from_str(f"{type_.__module__}.{type_.__qualname__}") + ) return result def parse_annotation_str( @@ -159,7 +164,9 @@ def _add_import(self, name: QualifiedName) -> None: return if len(name) == 1 and len(name[0]) == 0: return - if hasattr(builtins, name[0]): + if len(name) == 1 and hasattr(builtins, name[0]): + return + if len(name) > 0 and name[0] == "builtins": return if self.__current_class is not None and hasattr(self.__current_class, name[0]): return @@ -171,6 +178,8 @@ def _add_import(self, name: QualifiedName) -> None: if module_name is None: self.report_error(NameResolutionError(name)) return + if self.__current_module.__name__ == str(module_name): + return self.__extra_imports.add(Import(name=None, origin=module_name)) def _get_parent_module(self, name: QualifiedName) -> QualifiedName | None: @@ -498,6 +507,14 @@ def handle_value(self, value: Any) -> Value: result.repr = self._pattern.sub(r"<\g object>", result.repr) return result + def parse_value_str(self, value: str) -> Value | InvalidExpression: + result = super().parse_value_str(value) + if isinstance(result, Value): + result.repr = self._pattern.sub(r"<\g object>", result.repr) + else: + result.text = self._pattern.sub(r"<\g object>", result.text) + return result + class FixNumpyArrayDimAnnotation(IParser): __array_names: set[QualifiedName] = { @@ -867,6 +884,24 @@ def handle_class_member( return result +class WrapInvalidExpressions(IParser): + def parse_annotation_str( + self, annotation_str: str + ) -> ResolvedType | InvalidExpression | Value: + result = super().parse_annotation_str(annotation_str) + if not isinstance(result, InvalidExpression): + return result + + substitute_t = self.parse_annotation_str("typing.Any") + return ResolvedType( + QualifiedName.from_str("Annotated"), + parameters=[ + substitute_t, + result, + ], + ) + + class FixMissingFixedSizeImport(IParser): def parse_annotation_str( self, annotation_str: str @@ -887,8 +922,6 @@ def parse_annotation_str( except ValueError: pass else: - # call `handle_type` to trigger implicit import - self.handle_type(FixedSize) return self.handle_value(FixedSize(*dimensions)) return result diff --git a/pybind11_stubgen/parser/mixins/parse.py b/pybind11_stubgen/parser/mixins/parse.py index 64ea8df..00d87cd 100644 --- a/pybind11_stubgen/parser/mixins/parse.py +++ b/pybind11_stubgen/parser/mixins/parse.py @@ -1,9 +1,11 @@ from __future__ import annotations import ast +import datetime import inspect import re import types +import typing from typing import Any from pybind11_stubgen.parser.errors import ( @@ -34,6 +36,7 @@ TypeVar_, Value, ) +from pybind11_stubgen.typing_ext import DynamicSize, FixedSize _generic_args = [ Argument(name=Identifier("args"), variadic=True), @@ -250,16 +253,16 @@ def handle_function(self, path: QualifiedName, func: Any) -> list[Function]: func_args[arg_name].annotation = self.parse_annotation_str( annotation ) - elif not isinstance(annotation, type): - func_args[arg_name].annotation = self.handle_value(annotation) elif self._is_generic_alias(annotation): func_args[arg_name].annotation = self.parse_annotation_str( str(annotation) ) - else: + elif isinstance(annotation, type): func_args[arg_name].annotation = ResolvedType( name=self.handle_type(annotation), ) + else: + func_args[arg_name].annotation = self.handle_value(annotation) if "return" in func_args: returns = func_args["return"].annotation else: @@ -291,7 +294,10 @@ def _is_generic_alias(self, annotation: type) -> bool: generic_alias_t: type | None = getattr(types, "GenericAlias", None) if generic_alias_t is None: return False - return isinstance(annotation, generic_alias_t) + typing_generic_alias_t = type(typing.List[int]) + return isinstance(annotation, generic_alias_t) or isinstance( + annotation, typing_generic_alias_t + ) def handle_import(self, path: QualifiedName, origin: Any) -> Import | None: full_name = self._get_full_name(path, origin) @@ -370,6 +376,10 @@ def handle_value(self, value: Any) -> Value: return Value(repr=str(self.handle_type(value)), is_print_safe=True) if inspect.ismodule(value): return Value(repr=value.__name__, is_print_safe=True) + if isinstance(value, datetime.timedelta): + return Value(repr=repr(value), is_print_safe=True) + if isinstance(value, (FixedSize, DynamicSize)): + return Value(repr=repr(value), is_print_safe=True) return Value(repr=repr(value), is_print_safe=False) def handle_type(self, type_: type) -> QualifiedName: diff --git a/pybind11_stubgen/printer.py b/pybind11_stubgen/printer.py index 1f755aa..d45501e 100644 --- a/pybind11_stubgen/printer.py +++ b/pybind11_stubgen/printer.py @@ -19,6 +19,7 @@ Modifier, Module, Property, + QualifiedName, ResolvedType, TypeVar_, Value, @@ -30,8 +31,8 @@ def indent_lines(lines: list[str], by=4) -> list[str]: class Printer: - def __init__(self, invalid_expr_as_ellipses: bool): - self.invalid_expr_as_ellipses = invalid_expr_as_ellipses + def __init__(self): + self._need_typing_ext = False def print_alias(self, alias: Alias) -> list[str]: return [f"{alias.name} = {alias.origin}"] @@ -43,13 +44,12 @@ def print_attribute(self, attr: Attribute) -> list[str]: if attr.annotation is not None: parts.append(f": {self.print_annotation(attr.annotation)}") - if attr.value is not None and attr.value.is_print_safe: - parts.append(f" = {self.print_value(attr.value)}") - else: - if attr.annotation is None: - parts.append(" = ...") - if attr.value is not None: - parts.append(f" # value = {self.print_value(attr.value)}") + if attr.value is not None: + if attr.value.is_print_safe or attr.annotation is None: + parts.append(f" = {self.print_value(attr.value)}") + else: + repr_first_line = attr.value.repr.split("\n", 1)[0] + parts.append(f" # value = {repr_first_line}") return ["".join(parts)] @@ -202,40 +202,51 @@ def print_method(self, method: Method) -> list[str]: return result def print_module(self, module: Module) -> list[str]: - result = [] - - if module.doc is not None: - result.extend(self.print_docstring(module.doc)) - - for import_ in sorted(module.imports, key=lambda x: x.origin): - result.extend(self.print_import(import_)) + result_bottom = [] + tmp = self._need_typing_ext for sub_module in module.sub_modules: - result.extend(self.print_submodule_import(sub_module.name)) + result_bottom.extend(self.print_submodule_import(sub_module.name)) # Place __all__ above everything for attr in sorted(module.attributes, key=lambda a: a.name): if attr.name == "__all__": - result.extend(self.print_attribute(attr)) + result_bottom.extend(self.print_attribute(attr)) break for type_var in sorted(module.type_vars, key=lambda t: t.name): - result.extend(self.print_type_var(type_var)) + result_bottom.extend(self.print_type_var(type_var)) for class_ in sorted(module.classes, key=lambda c: c.name): - result.extend(self.print_class(class_)) + result_bottom.extend(self.print_class(class_)) for func in sorted(module.functions, key=lambda f: f.name): - result.extend(self.print_function(func)) + result_bottom.extend(self.print_function(func)) for attr in sorted(module.attributes, key=lambda a: a.name): if attr.name != "__all__": - result.extend(self.print_attribute(attr)) + result_bottom.extend(self.print_attribute(attr)) for alias in module.aliases: - result.extend(self.print_alias(alias)) + result_bottom.extend(self.print_alias(alias)) + + if self._need_typing_ext: + module.imports.add( + Import( + name=None, + origin=QualifiedName.from_str("pybind11_stubgen.typing_ext"), + ) + ) - return result + result_top = [] + if module.doc is not None: + result_top.extend(self.print_docstring(module.doc)) + + for import_ in sorted(module.imports, key=lambda x: x.origin): + result_top.extend(self.print_import(import_)) + + self._need_typing_ext = tmp + return result_top + result_bottom def print_property(self, prop: Property) -> list[str]: if not prop.getter: @@ -276,11 +287,10 @@ def print_property(self, prop: Property) -> list[str]: return result def print_value(self, value: Value) -> str: - split = value.repr.split("\n", 1) - if len(split) == 1: - return split[0] - else: - return split[0] + "..." + if value.is_print_safe: + return value.repr + self._need_typing_ext = True + return f"pybind11_stubgen.typing_ext.ValueExpr({repr(value.repr)})" def print_type(self, type_: ResolvedType) -> str: if ( @@ -312,6 +322,5 @@ def print_annotation(self, annotation: Annotation) -> str: raise AssertionError() def print_invalid_exp(self, invalid_expr: InvalidExpression) -> str: - if self.invalid_expr_as_ellipses: - return "..." - return invalid_expr.text + self._need_typing_ext = True + return f"pybind11_stubgen.typing_ext.InvalidExpr({repr(invalid_expr.text)})" diff --git a/pybind11_stubgen/typing_ext.py b/pybind11_stubgen/typing_ext.py index 72c7414..dd9e36b 100644 --- a/pybind11_stubgen/typing_ext.py +++ b/pybind11_stubgen/typing_ext.py @@ -1,5 +1,7 @@ from __future__ import annotations +from typing import Any + class FixedSize: def __init__(self, *dim: int): @@ -23,3 +25,17 @@ def __repr__(self): f"{self.__class__.__qualname__}" f"({', '.join(repr(d) for d in self.dim)})" ) + + +def InvalidExpr(expr: str) -> Any: + raise RuntimeError( + "The method exists only for annotation purposes in stub files. " + "Should never not be used at runtime" + ) + + +def ValueExpr(expr: str) -> Any: + raise RuntimeError( + "The method exists only for annotation purposes in stub files. " + "Should never not be used at runtime" + ) diff --git a/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/_bindings/duplicate_enum.pyi b/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/_bindings/duplicate_enum.pyi index 70eae65..3665a7e 100644 --- a/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/_bindings/duplicate_enum.pyi +++ b/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/_bindings/duplicate_enum.pyi @@ -2,6 +2,8 @@ from __future__ import annotations import typing +import pybind11_stubgen.typing_ext + __all__ = ["ConsoleForegroundColor", "Magenta", "accepts_ambiguous_enum"] class ConsoleForegroundColor: @@ -32,6 +34,10 @@ class ConsoleForegroundColor: @property def value(self) -> int: ... -def accepts_ambiguous_enum(color: ConsoleForegroundColor = ...) -> None: ... +def accepts_ambiguous_enum( + color: ConsoleForegroundColor = pybind11_stubgen.typing_ext.InvalidExpr( + "" + ), +) -> None: ... Magenta: ConsoleForegroundColor # value = diff --git a/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/_bindings/eigen.pyi b/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/_bindings/eigen.pyi index 92c4b1c..9f6fa55 100644 --- a/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/_bindings/eigen.pyi +++ b/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/_bindings/eigen.pyi @@ -3,6 +3,7 @@ from __future__ import annotations import typing import numpy +import pybind11_stubgen.typing_ext import scipy.sparse __all__ = [ @@ -25,12 +26,20 @@ N = typing.TypeVar("N", bound=int) def accept_matrix_int( arg0: numpy.ndarray[ - tuple[typing.Literal[3], typing.Literal[3]], numpy.dtype[numpy.int32] + tuple[ + typing.Literal[pybind11_stubgen.typing_ext.ValueExpr("3")], + typing.Literal[pybind11_stubgen.typing_ext.ValueExpr("3")], + ], + numpy.dtype[numpy.int32], ] ) -> None: ... def accept_vector_float64( arg0: numpy.ndarray[ - tuple[typing.Literal[3], typing.Literal[1]], numpy.dtype[numpy.float64] + tuple[ + typing.Literal[pybind11_stubgen.typing_ext.ValueExpr("3")], + typing.Literal[pybind11_stubgen.typing_ext.ValueExpr("1")], + ], + numpy.dtype[numpy.float64], ] ) -> None: ... def dense_matrix_c( @@ -41,30 +50,62 @@ def dense_matrix_r( ) -> numpy.ndarray[tuple[M, N], numpy.dtype[numpy.float32]]: ... def fixed_mutator_a( arg0: numpy.ndarray[ - tuple[typing.Literal[5], typing.Literal[6]], numpy.dtype[numpy.float32] + tuple[ + typing.Literal[pybind11_stubgen.typing_ext.ValueExpr("5")], + typing.Literal[pybind11_stubgen.typing_ext.ValueExpr("6")], + ], + numpy.dtype[numpy.float32], ] ) -> None: ... def fixed_mutator_c( arg0: numpy.ndarray[ - tuple[typing.Literal[5], typing.Literal[6]], numpy.dtype[numpy.float32] + tuple[ + typing.Literal[pybind11_stubgen.typing_ext.ValueExpr("5")], + typing.Literal[pybind11_stubgen.typing_ext.ValueExpr("6")], + ], + numpy.dtype[numpy.float32], ] ) -> None: ... def fixed_mutator_r( arg0: numpy.ndarray[ - tuple[typing.Literal[5], typing.Literal[6]], numpy.dtype[numpy.float32] + tuple[ + typing.Literal[pybind11_stubgen.typing_ext.ValueExpr("5")], + typing.Literal[pybind11_stubgen.typing_ext.ValueExpr("6")], + ], + numpy.dtype[numpy.float32], ] ) -> None: ... def four_col_matrix_r( - arg0: numpy.ndarray[tuple[M, typing.Literal[4]], numpy.dtype[numpy.float32]] -) -> numpy.ndarray[tuple[M, typing.Literal[4]], numpy.dtype[numpy.float32]]: ... + arg0: numpy.ndarray[ + tuple[M, typing.Literal[pybind11_stubgen.typing_ext.ValueExpr("4")]], + numpy.dtype[numpy.float32], + ] +) -> numpy.ndarray[ + tuple[M, typing.Literal[pybind11_stubgen.typing_ext.ValueExpr("4")]], + numpy.dtype[numpy.float32], +]: ... def four_row_matrix_r( - arg0: numpy.ndarray[tuple[typing.Literal[4], N], numpy.dtype[numpy.float32]] -) -> numpy.ndarray[tuple[typing.Literal[4], N], numpy.dtype[numpy.float32]]: ... + arg0: numpy.ndarray[ + tuple[typing.Literal[pybind11_stubgen.typing_ext.ValueExpr("4")], N], + numpy.dtype[numpy.float32], + ] +) -> numpy.ndarray[ + tuple[typing.Literal[pybind11_stubgen.typing_ext.ValueExpr("4")], N], + numpy.dtype[numpy.float32], +]: ... def get_matrix_int() -> numpy.ndarray[ - tuple[typing.Literal[3], typing.Literal[3]], numpy.dtype[numpy.int32] + tuple[ + typing.Literal[pybind11_stubgen.typing_ext.ValueExpr("3")], + typing.Literal[pybind11_stubgen.typing_ext.ValueExpr("3")], + ], + numpy.dtype[numpy.int32], ]: ... def get_vector_float64() -> numpy.ndarray[ - tuple[typing.Literal[3], typing.Literal[1]], numpy.dtype[numpy.float64] + tuple[ + typing.Literal[pybind11_stubgen.typing_ext.ValueExpr("3")], + typing.Literal[pybind11_stubgen.typing_ext.ValueExpr("1")], + ], + numpy.dtype[numpy.float64], ]: ... def sparse_matrix_c(arg0: scipy.sparse.csc_matrix) -> scipy.sparse.csc_matrix: ... def sparse_matrix_r(arg0: scipy.sparse.csr_matrix) -> scipy.sparse.csr_matrix: ... diff --git a/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/_bindings/flawed_bindings.pyi b/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/_bindings/flawed_bindings.pyi index 651a886..752f2ea 100644 --- a/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/_bindings/flawed_bindings.pyi +++ b/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/_bindings/flawed_bindings.pyi @@ -1,5 +1,9 @@ from __future__ import annotations +import typing + +import pybind11_stubgen.typing_ext + __all__ = [ "Enum", "Unbound", @@ -16,8 +20,32 @@ class Enum: class Unbound: pass -def accept_unbound_enum(arg0: ...) -> int: ... -def accept_unbound_enum_defaulted(x: Enum = ...) -> int: ... -def accept_unbound_type(arg0: tuple[..., int]) -> int: ... -def accept_unbound_type_defaulted(x: Unbound = ...) -> int: ... -def get_unbound_type() -> ...: ... +def accept_unbound_enum( + arg0: typing.Annotated[ + typing.Any, + pybind11_stubgen.typing_ext.InvalidExpr("(anonymous namespace)::Enum"), + ] +) -> int: ... +def accept_unbound_enum_defaulted( + x: Enum = pybind11_stubgen.typing_ext.InvalidExpr( + "" + ), +) -> int: ... +def accept_unbound_type( + arg0: tuple[ + typing.Annotated[ + typing.Any, + pybind11_stubgen.typing_ext.InvalidExpr("(anonymous namespace)::Unbound"), + ], + int, + ] +) -> int: ... +def accept_unbound_type_defaulted( + x: Unbound = pybind11_stubgen.typing_ext.InvalidExpr( + "" + ), +) -> int: ... +def get_unbound_type() -> typing.Annotated[ + typing.Any, + pybind11_stubgen.typing_ext.InvalidExpr("(anonymous namespace)::Unbound"), +]: ... diff --git a/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/_bindings/values.pyi b/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/_bindings/values.pyi index eb4a85a..1c01295 100644 --- a/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/_bindings/values.pyi +++ b/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/_bindings/values.pyi @@ -31,6 +31,6 @@ foolist: list # value = [, list_with_none: list = [None, 2, {}] none = None -t_10ms: datetime.timedelta # value = datetime.timedelta(microseconds=10000) -t_20ns: datetime.timedelta # value = datetime.timedelta(0) -t_30s: datetime.timedelta # value = datetime.timedelta(seconds=30) +t_10ms: datetime.timedelta = datetime.timedelta(microseconds=10000) +t_20ns: datetime.timedelta = datetime.timedelta(0) +t_30s: datetime.timedelta = datetime.timedelta(seconds=30) diff --git a/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/pure_python/functions.pyi b/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/pure_python/functions.pyi index a6c7165..320ddc7 100644 --- a/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/pure_python/functions.pyi +++ b/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/pure_python/functions.pyi @@ -3,6 +3,8 @@ from __future__ import annotations import sys as sys import typing as typing +import pybind11_stubgen.typing_ext + from demo.pure_python.functions_3_8_plus import args_mix from demo.pure_python.functions_3_9_plus import generic_alias_annotation @@ -24,8 +26,12 @@ class _Dummy: def foo(): ... def accept_frozenset(arg: frozenset[int | float]) -> int | None: ... -def builtin_function_as_default_arg(func: type(len) = len): ... -def function_as_default_arg(func: type(search) = search): ... +def builtin_function_as_default_arg( + func: pybind11_stubgen.typing_ext.ValueExpr("type(len)") = len, +): ... +def function_as_default_arg( + func: pybind11_stubgen.typing_ext.ValueExpr("type(search)") = search, +): ... def lambda_as_default_arg(callback=...): ... def search(a: int, b: list[int]) -> int: ... def static_method_as_default_arg(callback=_Dummy.foo): ... diff --git a/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/pure_python/functions_3_8_plus.pyi b/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/pure_python/functions_3_8_plus.pyi index dd9ffdc..3361a12 100644 --- a/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/pure_python/functions_3_8_plus.pyi +++ b/tests/stubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/pure_python/functions_3_8_plus.pyi @@ -11,5 +11,5 @@ def args_mix( *args: int, x: int = 1, y=int, - **kwargs: typing.Dict[int, str], + **kwargs: dict[int, str], ): ... diff --git a/tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/duplicate_enum.pyi b/tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/duplicate_enum.pyi index 70eae65..3665a7e 100644 --- a/tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/duplicate_enum.pyi +++ b/tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/duplicate_enum.pyi @@ -2,6 +2,8 @@ from __future__ import annotations import typing +import pybind11_stubgen.typing_ext + __all__ = ["ConsoleForegroundColor", "Magenta", "accepts_ambiguous_enum"] class ConsoleForegroundColor: @@ -32,6 +34,10 @@ class ConsoleForegroundColor: @property def value(self) -> int: ... -def accepts_ambiguous_enum(color: ConsoleForegroundColor = ...) -> None: ... +def accepts_ambiguous_enum( + color: ConsoleForegroundColor = pybind11_stubgen.typing_ext.InvalidExpr( + "" + ), +) -> None: ... Magenta: ConsoleForegroundColor # value = diff --git a/tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/flawed_bindings.pyi b/tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/flawed_bindings.pyi index 651a886..752f2ea 100644 --- a/tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/flawed_bindings.pyi +++ b/tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/flawed_bindings.pyi @@ -1,5 +1,9 @@ from __future__ import annotations +import typing + +import pybind11_stubgen.typing_ext + __all__ = [ "Enum", "Unbound", @@ -16,8 +20,32 @@ class Enum: class Unbound: pass -def accept_unbound_enum(arg0: ...) -> int: ... -def accept_unbound_enum_defaulted(x: Enum = ...) -> int: ... -def accept_unbound_type(arg0: tuple[..., int]) -> int: ... -def accept_unbound_type_defaulted(x: Unbound = ...) -> int: ... -def get_unbound_type() -> ...: ... +def accept_unbound_enum( + arg0: typing.Annotated[ + typing.Any, + pybind11_stubgen.typing_ext.InvalidExpr("(anonymous namespace)::Enum"), + ] +) -> int: ... +def accept_unbound_enum_defaulted( + x: Enum = pybind11_stubgen.typing_ext.InvalidExpr( + "" + ), +) -> int: ... +def accept_unbound_type( + arg0: tuple[ + typing.Annotated[ + typing.Any, + pybind11_stubgen.typing_ext.InvalidExpr("(anonymous namespace)::Unbound"), + ], + int, + ] +) -> int: ... +def accept_unbound_type_defaulted( + x: Unbound = pybind11_stubgen.typing_ext.InvalidExpr( + "" + ), +) -> int: ... +def get_unbound_type() -> typing.Annotated[ + typing.Any, + pybind11_stubgen.typing_ext.InvalidExpr("(anonymous namespace)::Unbound"), +]: ... diff --git a/tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/values.pyi b/tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/values.pyi index eb4a85a..1c01295 100644 --- a/tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/values.pyi +++ b/tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/values.pyi @@ -31,6 +31,6 @@ foolist: list # value = [, list_with_none: list = [None, 2, {}] none = None -t_10ms: datetime.timedelta # value = datetime.timedelta(microseconds=10000) -t_20ns: datetime.timedelta # value = datetime.timedelta(0) -t_30s: datetime.timedelta # value = datetime.timedelta(seconds=30) +t_10ms: datetime.timedelta = datetime.timedelta(microseconds=10000) +t_20ns: datetime.timedelta = datetime.timedelta(0) +t_30s: datetime.timedelta = datetime.timedelta(seconds=30) diff --git a/tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/pure_python/functions.pyi b/tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/pure_python/functions.pyi index a6c7165..320ddc7 100644 --- a/tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/pure_python/functions.pyi +++ b/tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/pure_python/functions.pyi @@ -3,6 +3,8 @@ from __future__ import annotations import sys as sys import typing as typing +import pybind11_stubgen.typing_ext + from demo.pure_python.functions_3_8_plus import args_mix from demo.pure_python.functions_3_9_plus import generic_alias_annotation @@ -24,8 +26,12 @@ class _Dummy: def foo(): ... def accept_frozenset(arg: frozenset[int | float]) -> int | None: ... -def builtin_function_as_default_arg(func: type(len) = len): ... -def function_as_default_arg(func: type(search) = search): ... +def builtin_function_as_default_arg( + func: pybind11_stubgen.typing_ext.ValueExpr("type(len)") = len, +): ... +def function_as_default_arg( + func: pybind11_stubgen.typing_ext.ValueExpr("type(search)") = search, +): ... def lambda_as_default_arg(callback=...): ... def search(a: int, b: list[int]) -> int: ... def static_method_as_default_arg(callback=_Dummy.foo): ... diff --git a/tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/pure_python/functions_3_8_plus.pyi b/tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/pure_python/functions_3_8_plus.pyi index dd9ffdc..3361a12 100644 --- a/tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/pure_python/functions_3_8_plus.pyi +++ b/tests/stubs/python-3.12/pybind11-master/numpy-array-wrap-with-annotated/demo/pure_python/functions_3_8_plus.pyi @@ -11,5 +11,5 @@ def args_mix( *args: int, x: int = 1, y=int, - **kwargs: typing.Dict[int, str], + **kwargs: dict[int, str], ): ... diff --git a/tests/stubs/python-3.12/pybind11-v2.11/numpy-array-wrap-with-annotated/demo/_bindings/duplicate_enum.pyi b/tests/stubs/python-3.12/pybind11-v2.11/numpy-array-wrap-with-annotated/demo/_bindings/duplicate_enum.pyi index 70eae65..3665a7e 100644 --- a/tests/stubs/python-3.12/pybind11-v2.11/numpy-array-wrap-with-annotated/demo/_bindings/duplicate_enum.pyi +++ b/tests/stubs/python-3.12/pybind11-v2.11/numpy-array-wrap-with-annotated/demo/_bindings/duplicate_enum.pyi @@ -2,6 +2,8 @@ from __future__ import annotations import typing +import pybind11_stubgen.typing_ext + __all__ = ["ConsoleForegroundColor", "Magenta", "accepts_ambiguous_enum"] class ConsoleForegroundColor: @@ -32,6 +34,10 @@ class ConsoleForegroundColor: @property def value(self) -> int: ... -def accepts_ambiguous_enum(color: ConsoleForegroundColor = ...) -> None: ... +def accepts_ambiguous_enum( + color: ConsoleForegroundColor = pybind11_stubgen.typing_ext.InvalidExpr( + "" + ), +) -> None: ... Magenta: ConsoleForegroundColor # value = diff --git a/tests/stubs/python-3.12/pybind11-v2.11/numpy-array-wrap-with-annotated/demo/_bindings/flawed_bindings.pyi b/tests/stubs/python-3.12/pybind11-v2.11/numpy-array-wrap-with-annotated/demo/_bindings/flawed_bindings.pyi index 651a886..752f2ea 100644 --- a/tests/stubs/python-3.12/pybind11-v2.11/numpy-array-wrap-with-annotated/demo/_bindings/flawed_bindings.pyi +++ b/tests/stubs/python-3.12/pybind11-v2.11/numpy-array-wrap-with-annotated/demo/_bindings/flawed_bindings.pyi @@ -1,5 +1,9 @@ from __future__ import annotations +import typing + +import pybind11_stubgen.typing_ext + __all__ = [ "Enum", "Unbound", @@ -16,8 +20,32 @@ class Enum: class Unbound: pass -def accept_unbound_enum(arg0: ...) -> int: ... -def accept_unbound_enum_defaulted(x: Enum = ...) -> int: ... -def accept_unbound_type(arg0: tuple[..., int]) -> int: ... -def accept_unbound_type_defaulted(x: Unbound = ...) -> int: ... -def get_unbound_type() -> ...: ... +def accept_unbound_enum( + arg0: typing.Annotated[ + typing.Any, + pybind11_stubgen.typing_ext.InvalidExpr("(anonymous namespace)::Enum"), + ] +) -> int: ... +def accept_unbound_enum_defaulted( + x: Enum = pybind11_stubgen.typing_ext.InvalidExpr( + "" + ), +) -> int: ... +def accept_unbound_type( + arg0: tuple[ + typing.Annotated[ + typing.Any, + pybind11_stubgen.typing_ext.InvalidExpr("(anonymous namespace)::Unbound"), + ], + int, + ] +) -> int: ... +def accept_unbound_type_defaulted( + x: Unbound = pybind11_stubgen.typing_ext.InvalidExpr( + "" + ), +) -> int: ... +def get_unbound_type() -> typing.Annotated[ + typing.Any, + pybind11_stubgen.typing_ext.InvalidExpr("(anonymous namespace)::Unbound"), +]: ... diff --git a/tests/stubs/python-3.12/pybind11-v2.11/numpy-array-wrap-with-annotated/demo/_bindings/values.pyi b/tests/stubs/python-3.12/pybind11-v2.11/numpy-array-wrap-with-annotated/demo/_bindings/values.pyi index eb4a85a..1c01295 100644 --- a/tests/stubs/python-3.12/pybind11-v2.11/numpy-array-wrap-with-annotated/demo/_bindings/values.pyi +++ b/tests/stubs/python-3.12/pybind11-v2.11/numpy-array-wrap-with-annotated/demo/_bindings/values.pyi @@ -31,6 +31,6 @@ foolist: list # value = [, list_with_none: list = [None, 2, {}] none = None -t_10ms: datetime.timedelta # value = datetime.timedelta(microseconds=10000) -t_20ns: datetime.timedelta # value = datetime.timedelta(0) -t_30s: datetime.timedelta # value = datetime.timedelta(seconds=30) +t_10ms: datetime.timedelta = datetime.timedelta(microseconds=10000) +t_20ns: datetime.timedelta = datetime.timedelta(0) +t_30s: datetime.timedelta = datetime.timedelta(seconds=30) diff --git a/tests/stubs/python-3.12/pybind11-v2.11/numpy-array-wrap-with-annotated/demo/pure_python/functions.pyi b/tests/stubs/python-3.12/pybind11-v2.11/numpy-array-wrap-with-annotated/demo/pure_python/functions.pyi index a6c7165..320ddc7 100644 --- a/tests/stubs/python-3.12/pybind11-v2.11/numpy-array-wrap-with-annotated/demo/pure_python/functions.pyi +++ b/tests/stubs/python-3.12/pybind11-v2.11/numpy-array-wrap-with-annotated/demo/pure_python/functions.pyi @@ -3,6 +3,8 @@ from __future__ import annotations import sys as sys import typing as typing +import pybind11_stubgen.typing_ext + from demo.pure_python.functions_3_8_plus import args_mix from demo.pure_python.functions_3_9_plus import generic_alias_annotation @@ -24,8 +26,12 @@ class _Dummy: def foo(): ... def accept_frozenset(arg: frozenset[int | float]) -> int | None: ... -def builtin_function_as_default_arg(func: type(len) = len): ... -def function_as_default_arg(func: type(search) = search): ... +def builtin_function_as_default_arg( + func: pybind11_stubgen.typing_ext.ValueExpr("type(len)") = len, +): ... +def function_as_default_arg( + func: pybind11_stubgen.typing_ext.ValueExpr("type(search)") = search, +): ... def lambda_as_default_arg(callback=...): ... def search(a: int, b: list[int]) -> int: ... def static_method_as_default_arg(callback=_Dummy.foo): ... diff --git a/tests/stubs/python-3.12/pybind11-v2.11/numpy-array-wrap-with-annotated/demo/pure_python/functions_3_8_plus.pyi b/tests/stubs/python-3.12/pybind11-v2.11/numpy-array-wrap-with-annotated/demo/pure_python/functions_3_8_plus.pyi index dd9ffdc..3361a12 100644 --- a/tests/stubs/python-3.12/pybind11-v2.11/numpy-array-wrap-with-annotated/demo/pure_python/functions_3_8_plus.pyi +++ b/tests/stubs/python-3.12/pybind11-v2.11/numpy-array-wrap-with-annotated/demo/pure_python/functions_3_8_plus.pyi @@ -11,5 +11,5 @@ def args_mix( *args: int, x: int = 1, y=int, - **kwargs: typing.Dict[int, str], + **kwargs: dict[int, str], ): ... diff --git a/tests/stubs/python-3.12/pybind11-v2.9/numpy-array-wrap-with-annotated/demo/_bindings/duplicate_enum.pyi b/tests/stubs/python-3.12/pybind11-v2.9/numpy-array-wrap-with-annotated/demo/_bindings/duplicate_enum.pyi index 70eae65..3665a7e 100644 --- a/tests/stubs/python-3.12/pybind11-v2.9/numpy-array-wrap-with-annotated/demo/_bindings/duplicate_enum.pyi +++ b/tests/stubs/python-3.12/pybind11-v2.9/numpy-array-wrap-with-annotated/demo/_bindings/duplicate_enum.pyi @@ -2,6 +2,8 @@ from __future__ import annotations import typing +import pybind11_stubgen.typing_ext + __all__ = ["ConsoleForegroundColor", "Magenta", "accepts_ambiguous_enum"] class ConsoleForegroundColor: @@ -32,6 +34,10 @@ class ConsoleForegroundColor: @property def value(self) -> int: ... -def accepts_ambiguous_enum(color: ConsoleForegroundColor = ...) -> None: ... +def accepts_ambiguous_enum( + color: ConsoleForegroundColor = pybind11_stubgen.typing_ext.InvalidExpr( + "" + ), +) -> None: ... Magenta: ConsoleForegroundColor # value = diff --git a/tests/stubs/python-3.12/pybind11-v2.9/numpy-array-wrap-with-annotated/demo/_bindings/flawed_bindings.pyi b/tests/stubs/python-3.12/pybind11-v2.9/numpy-array-wrap-with-annotated/demo/_bindings/flawed_bindings.pyi index 651a886..752f2ea 100644 --- a/tests/stubs/python-3.12/pybind11-v2.9/numpy-array-wrap-with-annotated/demo/_bindings/flawed_bindings.pyi +++ b/tests/stubs/python-3.12/pybind11-v2.9/numpy-array-wrap-with-annotated/demo/_bindings/flawed_bindings.pyi @@ -1,5 +1,9 @@ from __future__ import annotations +import typing + +import pybind11_stubgen.typing_ext + __all__ = [ "Enum", "Unbound", @@ -16,8 +20,32 @@ class Enum: class Unbound: pass -def accept_unbound_enum(arg0: ...) -> int: ... -def accept_unbound_enum_defaulted(x: Enum = ...) -> int: ... -def accept_unbound_type(arg0: tuple[..., int]) -> int: ... -def accept_unbound_type_defaulted(x: Unbound = ...) -> int: ... -def get_unbound_type() -> ...: ... +def accept_unbound_enum( + arg0: typing.Annotated[ + typing.Any, + pybind11_stubgen.typing_ext.InvalidExpr("(anonymous namespace)::Enum"), + ] +) -> int: ... +def accept_unbound_enum_defaulted( + x: Enum = pybind11_stubgen.typing_ext.InvalidExpr( + "" + ), +) -> int: ... +def accept_unbound_type( + arg0: tuple[ + typing.Annotated[ + typing.Any, + pybind11_stubgen.typing_ext.InvalidExpr("(anonymous namespace)::Unbound"), + ], + int, + ] +) -> int: ... +def accept_unbound_type_defaulted( + x: Unbound = pybind11_stubgen.typing_ext.InvalidExpr( + "" + ), +) -> int: ... +def get_unbound_type() -> typing.Annotated[ + typing.Any, + pybind11_stubgen.typing_ext.InvalidExpr("(anonymous namespace)::Unbound"), +]: ... diff --git a/tests/stubs/python-3.12/pybind11-v2.9/numpy-array-wrap-with-annotated/demo/_bindings/values.pyi b/tests/stubs/python-3.12/pybind11-v2.9/numpy-array-wrap-with-annotated/demo/_bindings/values.pyi index eb4a85a..1c01295 100644 --- a/tests/stubs/python-3.12/pybind11-v2.9/numpy-array-wrap-with-annotated/demo/_bindings/values.pyi +++ b/tests/stubs/python-3.12/pybind11-v2.9/numpy-array-wrap-with-annotated/demo/_bindings/values.pyi @@ -31,6 +31,6 @@ foolist: list # value = [, list_with_none: list = [None, 2, {}] none = None -t_10ms: datetime.timedelta # value = datetime.timedelta(microseconds=10000) -t_20ns: datetime.timedelta # value = datetime.timedelta(0) -t_30s: datetime.timedelta # value = datetime.timedelta(seconds=30) +t_10ms: datetime.timedelta = datetime.timedelta(microseconds=10000) +t_20ns: datetime.timedelta = datetime.timedelta(0) +t_30s: datetime.timedelta = datetime.timedelta(seconds=30) diff --git a/tests/stubs/python-3.12/pybind11-v2.9/numpy-array-wrap-with-annotated/demo/pure_python/functions.pyi b/tests/stubs/python-3.12/pybind11-v2.9/numpy-array-wrap-with-annotated/demo/pure_python/functions.pyi index a6c7165..320ddc7 100644 --- a/tests/stubs/python-3.12/pybind11-v2.9/numpy-array-wrap-with-annotated/demo/pure_python/functions.pyi +++ b/tests/stubs/python-3.12/pybind11-v2.9/numpy-array-wrap-with-annotated/demo/pure_python/functions.pyi @@ -3,6 +3,8 @@ from __future__ import annotations import sys as sys import typing as typing +import pybind11_stubgen.typing_ext + from demo.pure_python.functions_3_8_plus import args_mix from demo.pure_python.functions_3_9_plus import generic_alias_annotation @@ -24,8 +26,12 @@ class _Dummy: def foo(): ... def accept_frozenset(arg: frozenset[int | float]) -> int | None: ... -def builtin_function_as_default_arg(func: type(len) = len): ... -def function_as_default_arg(func: type(search) = search): ... +def builtin_function_as_default_arg( + func: pybind11_stubgen.typing_ext.ValueExpr("type(len)") = len, +): ... +def function_as_default_arg( + func: pybind11_stubgen.typing_ext.ValueExpr("type(search)") = search, +): ... def lambda_as_default_arg(callback=...): ... def search(a: int, b: list[int]) -> int: ... def static_method_as_default_arg(callback=_Dummy.foo): ... diff --git a/tests/stubs/python-3.12/pybind11-v2.9/numpy-array-wrap-with-annotated/demo/pure_python/functions_3_8_plus.pyi b/tests/stubs/python-3.12/pybind11-v2.9/numpy-array-wrap-with-annotated/demo/pure_python/functions_3_8_plus.pyi index dd9ffdc..3361a12 100644 --- a/tests/stubs/python-3.12/pybind11-v2.9/numpy-array-wrap-with-annotated/demo/pure_python/functions_3_8_plus.pyi +++ b/tests/stubs/python-3.12/pybind11-v2.9/numpy-array-wrap-with-annotated/demo/pure_python/functions_3_8_plus.pyi @@ -11,5 +11,5 @@ def args_mix( *args: int, x: int = 1, y=int, - **kwargs: typing.Dict[int, str], + **kwargs: dict[int, str], ): ... diff --git a/tests/stubs/python-3.7/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/duplicate_enum.pyi b/tests/stubs/python-3.7/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/duplicate_enum.pyi index 70eae65..3665a7e 100644 --- a/tests/stubs/python-3.7/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/duplicate_enum.pyi +++ b/tests/stubs/python-3.7/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/duplicate_enum.pyi @@ -2,6 +2,8 @@ from __future__ import annotations import typing +import pybind11_stubgen.typing_ext + __all__ = ["ConsoleForegroundColor", "Magenta", "accepts_ambiguous_enum"] class ConsoleForegroundColor: @@ -32,6 +34,10 @@ class ConsoleForegroundColor: @property def value(self) -> int: ... -def accepts_ambiguous_enum(color: ConsoleForegroundColor = ...) -> None: ... +def accepts_ambiguous_enum( + color: ConsoleForegroundColor = pybind11_stubgen.typing_ext.InvalidExpr( + "" + ), +) -> None: ... Magenta: ConsoleForegroundColor # value = diff --git a/tests/stubs/python-3.7/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/flawed_bindings.pyi b/tests/stubs/python-3.7/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/flawed_bindings.pyi index 651a886..b0cc0b8 100644 --- a/tests/stubs/python-3.7/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/flawed_bindings.pyi +++ b/tests/stubs/python-3.7/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/flawed_bindings.pyi @@ -1,5 +1,10 @@ from __future__ import annotations +import typing + +import pybind11_stubgen.typing_ext +import typing_extensions + __all__ = [ "Enum", "Unbound", @@ -16,8 +21,32 @@ class Enum: class Unbound: pass -def accept_unbound_enum(arg0: ...) -> int: ... -def accept_unbound_enum_defaulted(x: Enum = ...) -> int: ... -def accept_unbound_type(arg0: tuple[..., int]) -> int: ... -def accept_unbound_type_defaulted(x: Unbound = ...) -> int: ... -def get_unbound_type() -> ...: ... +def accept_unbound_enum( + arg0: typing_extensions.Annotated[ + typing.Any, + pybind11_stubgen.typing_ext.InvalidExpr("(anonymous namespace)::Enum"), + ] +) -> int: ... +def accept_unbound_enum_defaulted( + x: Enum = pybind11_stubgen.typing_ext.InvalidExpr( + "" + ), +) -> int: ... +def accept_unbound_type( + arg0: tuple[ + typing_extensions.Annotated[ + typing.Any, + pybind11_stubgen.typing_ext.InvalidExpr("(anonymous namespace)::Unbound"), + ], + int, + ] +) -> int: ... +def accept_unbound_type_defaulted( + x: Unbound = pybind11_stubgen.typing_ext.InvalidExpr( + "" + ), +) -> int: ... +def get_unbound_type() -> typing_extensions.Annotated[ + typing.Any, + pybind11_stubgen.typing_ext.InvalidExpr("(anonymous namespace)::Unbound"), +]: ... diff --git a/tests/stubs/python-3.7/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/values.pyi b/tests/stubs/python-3.7/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/values.pyi index eb4a85a..1c01295 100644 --- a/tests/stubs/python-3.7/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/values.pyi +++ b/tests/stubs/python-3.7/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/values.pyi @@ -31,6 +31,6 @@ foolist: list # value = [, list_with_none: list = [None, 2, {}] none = None -t_10ms: datetime.timedelta # value = datetime.timedelta(microseconds=10000) -t_20ns: datetime.timedelta # value = datetime.timedelta(0) -t_30s: datetime.timedelta # value = datetime.timedelta(seconds=30) +t_10ms: datetime.timedelta = datetime.timedelta(microseconds=10000) +t_20ns: datetime.timedelta = datetime.timedelta(0) +t_30s: datetime.timedelta = datetime.timedelta(seconds=30) diff --git a/tests/stubs/python-3.7/pybind11-master/numpy-array-wrap-with-annotated/demo/pure_python/functions.pyi b/tests/stubs/python-3.7/pybind11-master/numpy-array-wrap-with-annotated/demo/pure_python/functions.pyi index ec036d0..b230b1d 100644 --- a/tests/stubs/python-3.7/pybind11-master/numpy-array-wrap-with-annotated/demo/pure_python/functions.pyi +++ b/tests/stubs/python-3.7/pybind11-master/numpy-array-wrap-with-annotated/demo/pure_python/functions.pyi @@ -3,6 +3,8 @@ from __future__ import annotations import sys as sys import typing as typing +import pybind11_stubgen.typing_ext + __all__ = [ "accept_frozenset", "builtin_function_as_default_arg", @@ -19,8 +21,12 @@ class _Dummy: def foo(): ... def accept_frozenset(arg: frozenset[int | float]) -> int | None: ... -def builtin_function_as_default_arg(func: type(len) = len): ... -def function_as_default_arg(func: type(search) = search): ... +def builtin_function_as_default_arg( + func: pybind11_stubgen.typing_ext.ValueExpr("type(len)") = len, +): ... +def function_as_default_arg( + func: pybind11_stubgen.typing_ext.ValueExpr("type(search)") = search, +): ... def lambda_as_default_arg(callback=...): ... def search(a: int, b: list[int]) -> int: ... def static_method_as_default_arg(callback=_Dummy.foo): ... diff --git a/tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/duplicate_enum.pyi b/tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/duplicate_enum.pyi index 70eae65..3665a7e 100644 --- a/tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/duplicate_enum.pyi +++ b/tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/duplicate_enum.pyi @@ -2,6 +2,8 @@ from __future__ import annotations import typing +import pybind11_stubgen.typing_ext + __all__ = ["ConsoleForegroundColor", "Magenta", "accepts_ambiguous_enum"] class ConsoleForegroundColor: @@ -32,6 +34,10 @@ class ConsoleForegroundColor: @property def value(self) -> int: ... -def accepts_ambiguous_enum(color: ConsoleForegroundColor = ...) -> None: ... +def accepts_ambiguous_enum( + color: ConsoleForegroundColor = pybind11_stubgen.typing_ext.InvalidExpr( + "" + ), +) -> None: ... Magenta: ConsoleForegroundColor # value = diff --git a/tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/flawed_bindings.pyi b/tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/flawed_bindings.pyi index 651a886..b0cc0b8 100644 --- a/tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/flawed_bindings.pyi +++ b/tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/flawed_bindings.pyi @@ -1,5 +1,10 @@ from __future__ import annotations +import typing + +import pybind11_stubgen.typing_ext +import typing_extensions + __all__ = [ "Enum", "Unbound", @@ -16,8 +21,32 @@ class Enum: class Unbound: pass -def accept_unbound_enum(arg0: ...) -> int: ... -def accept_unbound_enum_defaulted(x: Enum = ...) -> int: ... -def accept_unbound_type(arg0: tuple[..., int]) -> int: ... -def accept_unbound_type_defaulted(x: Unbound = ...) -> int: ... -def get_unbound_type() -> ...: ... +def accept_unbound_enum( + arg0: typing_extensions.Annotated[ + typing.Any, + pybind11_stubgen.typing_ext.InvalidExpr("(anonymous namespace)::Enum"), + ] +) -> int: ... +def accept_unbound_enum_defaulted( + x: Enum = pybind11_stubgen.typing_ext.InvalidExpr( + "" + ), +) -> int: ... +def accept_unbound_type( + arg0: tuple[ + typing_extensions.Annotated[ + typing.Any, + pybind11_stubgen.typing_ext.InvalidExpr("(anonymous namespace)::Unbound"), + ], + int, + ] +) -> int: ... +def accept_unbound_type_defaulted( + x: Unbound = pybind11_stubgen.typing_ext.InvalidExpr( + "" + ), +) -> int: ... +def get_unbound_type() -> typing_extensions.Annotated[ + typing.Any, + pybind11_stubgen.typing_ext.InvalidExpr("(anonymous namespace)::Unbound"), +]: ... diff --git a/tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/values.pyi b/tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/values.pyi index eb4a85a..1c01295 100644 --- a/tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/values.pyi +++ b/tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/_bindings/values.pyi @@ -31,6 +31,6 @@ foolist: list # value = [, list_with_none: list = [None, 2, {}] none = None -t_10ms: datetime.timedelta # value = datetime.timedelta(microseconds=10000) -t_20ns: datetime.timedelta # value = datetime.timedelta(0) -t_30s: datetime.timedelta # value = datetime.timedelta(seconds=30) +t_10ms: datetime.timedelta = datetime.timedelta(microseconds=10000) +t_20ns: datetime.timedelta = datetime.timedelta(0) +t_30s: datetime.timedelta = datetime.timedelta(seconds=30) diff --git a/tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/pure_python/functions.pyi b/tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/pure_python/functions.pyi index 934f822..40a66e9 100644 --- a/tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/pure_python/functions.pyi +++ b/tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/pure_python/functions.pyi @@ -3,6 +3,8 @@ from __future__ import annotations import sys as sys import typing as typing +import pybind11_stubgen.typing_ext + from demo.pure_python.functions_3_8_plus import args_mix __all__ = [ @@ -22,8 +24,12 @@ class _Dummy: def foo(): ... def accept_frozenset(arg: frozenset[int | float]) -> int | None: ... -def builtin_function_as_default_arg(func: type(len) = len): ... -def function_as_default_arg(func: type(search) = search): ... +def builtin_function_as_default_arg( + func: pybind11_stubgen.typing_ext.ValueExpr("type(len)") = len, +): ... +def function_as_default_arg( + func: pybind11_stubgen.typing_ext.ValueExpr("type(search)") = search, +): ... def lambda_as_default_arg(callback=...): ... def search(a: int, b: list[int]) -> int: ... def static_method_as_default_arg(callback=_Dummy.foo): ... diff --git a/tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/pure_python/functions_3_8_plus.pyi b/tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/pure_python/functions_3_8_plus.pyi index dd9ffdc..4b91799 100644 --- a/tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/pure_python/functions_3_8_plus.pyi +++ b/tests/stubs/python-3.8/pybind11-master/numpy-array-wrap-with-annotated/demo/pure_python/functions_3_8_plus.pyi @@ -2,6 +2,8 @@ from __future__ import annotations import typing as typing +import pybind11_stubgen.typing_ext + __all__ = ["args_mix", "typing"] def args_mix( @@ -11,5 +13,5 @@ def args_mix( *args: int, x: int = 1, y=int, - **kwargs: typing.Dict[int, str], + **kwargs: pybind11_stubgen.typing_ext.ValueExpr("typing.Dict[int, str]"), ): ...