Merge branch 'master' into sh_merge_master

This commit is contained in:
Ralf W. Grosse-Kunstleve 2023-11-07 23:44:24 -08:00
commit 124b62a087
7 changed files with 34 additions and 33 deletions

View File

@ -25,23 +25,18 @@ repos:
# Clang format the codebase automatically # Clang format the codebase automatically
- repo: https://github.com/pre-commit/mirrors-clang-format - repo: https://github.com/pre-commit/mirrors-clang-format
rev: "v17.0.3" rev: "v17.0.4"
hooks: hooks:
- id: clang-format - id: clang-format
types_or: [c++, c, cuda] types_or: [c++, c, cuda]
# Black, the code formatter, natively supports pre-commit # Ruff, the Python auto-correcting linter/formatter written in Rust
- repo: https://github.com/psf/black-pre-commit-mirror
rev: "23.10.1" # Keep in sync with blacken-docs
hooks:
- id: black
# Ruff, the Python auto-correcting linter written in Rust
- repo: https://github.com/astral-sh/ruff-pre-commit - repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.2 rev: v0.1.4
hooks: hooks:
- id: ruff - id: ruff
args: ["--fix", "--show-fixes"] args: ["--fix", "--show-fixes"]
- id: ruff-format
# Check static types with mypy # Check static types with mypy
- repo: https://github.com/pre-commit/mirrors-mypy - repo: https://github.com/pre-commit/mirrors-mypy
@ -89,7 +84,7 @@ repos:
hooks: hooks:
- id: blacken-docs - id: blacken-docs
additional_dependencies: additional_dependencies:
- black==23.3.0 # keep in sync with black hook - black==23.*
# Changes tabs to spaces # Changes tabs to spaces
- repo: https://github.com/Lucas-C/pre-commit-hooks - repo: https://github.com/Lucas-C/pre-commit-hooks

View File

@ -3011,10 +3011,15 @@ get_type_override(const void *this_ptr, const type_info *this_type, const char *
if ((std::string) str(f_code->co_name) == name && f_code->co_argcount > 0) { if ((std::string) str(f_code->co_name) == name && f_code->co_argcount > 0) {
PyObject *locals = PyEval_GetLocals(); PyObject *locals = PyEval_GetLocals();
if (locals != nullptr) { if (locals != nullptr) {
# if PY_VERSION_HEX >= 0x030b0000
PyObject *co_varnames = PyCode_GetVarnames(f_code);
# else
PyObject *co_varnames = PyObject_GetAttrString((PyObject *) f_code, "co_varnames"); PyObject *co_varnames = PyObject_GetAttrString((PyObject *) f_code, "co_varnames");
# endif
PyObject *self_arg = PyTuple_GET_ITEM(co_varnames, 0); PyObject *self_arg = PyTuple_GET_ITEM(co_varnames, 0);
Py_DECREF(co_varnames); Py_DECREF(co_varnames);
PyObject *self_caller = dict_getitem(locals, self_arg); PyObject *self_caller = dict_getitem(locals, self_arg);
Py_DECREF(locals);
if (self_caller == self.ptr()) { if (self_caller == self.ptr()) {
Py_DECREF(f_code); Py_DECREF(f_code);
Py_DECREF(frame); Py_DECREF(frame);

View File

@ -66,7 +66,9 @@ try:
from setuptools import Extension as _Extension from setuptools import Extension as _Extension
from setuptools.command.build_ext import build_ext as _build_ext from setuptools.command.build_ext import build_ext as _build_ext
except ImportError: except ImportError:
from distutils.command.build_ext import build_ext as _build_ext # type: ignore[assignment] from distutils.command.build_ext import ( # type: ignore[assignment]
build_ext as _build_ext,
)
from distutils.extension import Extension as _Extension # type: ignore[assignment] from distutils.extension import Extension as _Extension # type: ignore[assignment]
import distutils.ccompiler import distutils.ccompiler

View File

@ -60,7 +60,6 @@ messages_control.disable = [
[tool.ruff] [tool.ruff]
target-version = "py37" target-version = "py37"
src = ["src"] src = ["src"]
line-length = 120
[tool.ruff.lint] [tool.ruff.lint]
extend-select = [ extend-select = [
@ -71,7 +70,6 @@ extend-select = [
"C4", # flake8-comprehensions "C4", # flake8-comprehensions
"EM", # flake8-errmsg "EM", # flake8-errmsg
"ICN", # flake8-import-conventions "ICN", # flake8-import-conventions
"ISC", # flake8-implicit-str-concat
"PGH", # pygrep-hooks "PGH", # pygrep-hooks
"PIE", # flake8-pie "PIE", # flake8-pie
"PL", # pylint "PL", # pylint
@ -90,7 +88,6 @@ ignore = [
"SIM118", # iter(x) is not always the same as iter(x.keys()) "SIM118", # iter(x) is not always the same as iter(x.keys())
] ]
unfixable = ["T20"] unfixable = ["T20"]
exclude = []
isort.known-first-party = ["env", "pybind11_cross_module_tests", "pybind11_tests"] isort.known-first-party = ["env", "pybind11_cross_module_tests", "pybind11_tests"]
[tool.ruff.lint.per-file-ignores] [tool.ruff.lint.per-file-ignores]

View File

@ -60,9 +60,7 @@ Members:
ETwo : Docstring for ETwo ETwo : Docstring for ETwo
EThree : Docstring for EThree""".split( EThree : Docstring for EThree""".split("\n"):
"\n"
):
assert docstring_line in m.UnscopedEnum.__doc__ assert docstring_line in m.UnscopedEnum.__doc__
# Unscoped enums will accept ==/!= int comparisons # Unscoped enums will accept ==/!= int comparisons

View File

@ -232,25 +232,29 @@ def test_no_mixed_overloads():
with pytest.raises(RuntimeError) as excinfo: with pytest.raises(RuntimeError) as excinfo:
m.ExampleMandA.add_mixed_overloads1() m.ExampleMandA.add_mixed_overloads1()
assert str( assert (
excinfo.value str(excinfo.value)
) == "overloading a method with both static and instance methods is not supported; " + ( == "overloading a method with both static and instance methods is not supported; "
"#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for more details" + (
if not detailed_error_messages_enabled "#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for more details"
else "error while attempting to bind static method ExampleMandA.overload_mixed1" if not detailed_error_messages_enabled
"(arg0: float) -> str" else "error while attempting to bind static method ExampleMandA.overload_mixed1"
"(arg0: float) -> str"
)
) )
with pytest.raises(RuntimeError) as excinfo: with pytest.raises(RuntimeError) as excinfo:
m.ExampleMandA.add_mixed_overloads2() m.ExampleMandA.add_mixed_overloads2()
assert str( assert (
excinfo.value str(excinfo.value)
) == "overloading a method with both static and instance methods is not supported; " + ( == "overloading a method with both static and instance methods is not supported; "
"#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for more details" + (
if not detailed_error_messages_enabled "#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for more details"
else "error while attempting to bind instance method ExampleMandA.overload_mixed2" if not detailed_error_messages_enabled
"(self: pybind11_tests.methods_and_attributes.ExampleMandA, arg0: int, arg1: int)" else "error while attempting to bind instance method ExampleMandA.overload_mixed2"
" -> str" "(self: pybind11_tests.methods_and_attributes.ExampleMandA, arg0: int, arg1: int)"
" -> str"
)
) )

View File

@ -149,7 +149,7 @@ default is ``MODULE``. There are several options:
``OPT_SIZE`` ``OPT_SIZE``
Optimize for size, even if the ``CMAKE_BUILD_TYPE`` is not ``MinSizeRel``. Optimize for size, even if the ``CMAKE_BUILD_TYPE`` is not ``MinSizeRel``.
``THIN_LTO`` ``THIN_LTO``
Use thin TLO instead of regular if there's a choice (pybind11's selection Use thin LTO instead of regular if there's a choice (pybind11's selection
is disabled if ``CMAKE_INTERPROCEDURAL_OPTIMIZATIONS`` is set). is disabled if ``CMAKE_INTERPROCEDURAL_OPTIMIZATIONS`` is set).
``WITHOUT_SOABI`` ``WITHOUT_SOABI``
Disable the SOABI component (``PYBIND11_NEWPYTHON`` mode only). Disable the SOABI component (``PYBIND11_NEWPYTHON`` mode only).