Merge branch 'master' into sh_merge_master

This commit is contained in:
Ralf W. Grosse-Kunstleve 2023-10-26 22:38:47 -07:00
commit f8ea68f242
6 changed files with 25 additions and 23 deletions

View File

@ -25,27 +25,27 @@ 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: "v16.0.6" rev: "v17.0.3"
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 # Black, the code formatter, natively supports pre-commit
- repo: https://github.com/psf/black-pre-commit-mirror - repo: https://github.com/psf/black-pre-commit-mirror
rev: "23.9.1" # Keep in sync with blacken-docs rev: "23.10.1" # Keep in sync with blacken-docs
hooks: hooks:
- id: black - id: black
# Ruff, the Python auto-correcting linter written in Rust # 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.0.292 rev: v0.1.2
hooks: hooks:
- id: ruff - id: ruff
args: ["--fix", "--show-fixes"] args: ["--fix", "--show-fixes"]
# 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
rev: "v1.5.1" rev: "v1.6.1"
hooks: hooks:
- id: mypy - id: mypy
args: [] args: []
@ -67,7 +67,7 @@ repos:
# Standard hooks # Standard hooks
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.4.0" rev: "v4.5.0"
hooks: hooks:
- id: check-added-large-files - id: check-added-large-files
- id: check-case-conflict - id: check-case-conflict
@ -100,7 +100,7 @@ repos:
# Avoid directional quotes # Avoid directional quotes
- repo: https://github.com/sirosen/texthooks - repo: https://github.com/sirosen/texthooks
rev: "0.5.0" rev: "0.6.2"
hooks: hooks:
- id: fix-ligatures - id: fix-ligatures
- id: fix-smartquotes - id: fix-smartquotes
@ -149,7 +149,7 @@ repos:
# PyLint has native support - not always usable, but works for us # PyLint has native support - not always usable, but works for us
- repo: https://github.com/PyCQA/pylint - repo: https://github.com/PyCQA/pylint
rev: "v3.0.0" rev: "v3.0.1"
hooks: hooks:
- id: pylint - id: pylint
files: ^pybind11 files: ^pybind11

View File

@ -486,8 +486,10 @@ PYBIND11_NOINLINE handle get_object_handle(const void *ptr, const detail::type_i
inline PyThreadState *get_thread_state_unchecked() { inline PyThreadState *get_thread_state_unchecked() {
#if defined(PYPY_VERSION) #if defined(PYPY_VERSION)
return PyThreadState_GET(); return PyThreadState_GET();
#else #elif PY_VERSION_HEX < 0x030D0000
return _PyThreadState_UncheckedGet(); return _PyThreadState_UncheckedGet();
#else
return PyThreadState_GetUnchecked();
#endif #endif
} }

View File

@ -305,19 +305,19 @@ private:
"https://pybind11.readthedocs.io/en/stable/advanced/" "https://pybind11.readthedocs.io/en/stable/advanced/"
"misc.html#common-sources-of-global-interpreter-lock-errors for debugging advice.\n" "misc.html#common-sources-of-global-interpreter-lock-errors for debugging advice.\n"
"If you are convinced there is no bug in your code, you can #define " "If you are convinced there is no bug in your code, you can #define "
"PYBIND11_NO_ASSERT_GIL_HELD_INCREF_DECREF" "PYBIND11_NO_ASSERT_GIL_HELD_INCREF_DECREF "
"to disable this check. In that case you have to ensure this #define is consistently " "to disable this check. In that case you have to ensure this #define is consistently "
"used for all translation units linked into a given pybind11 extension, otherwise " "used for all translation units linked into a given pybind11 extension, otherwise "
"there will be ODR violations.", "there will be ODR violations.",
function_name.c_str()); function_name.c_str());
fflush(stderr);
if (Py_TYPE(m_ptr)->tp_name != nullptr) { if (Py_TYPE(m_ptr)->tp_name != nullptr) {
fprintf(stderr, fprintf(stderr,
"The failing %s call was triggered on a %s object.\n", " The failing %s call was triggered on a %s object.",
function_name.c_str(), function_name.c_str(),
Py_TYPE(m_ptr)->tp_name); Py_TYPE(m_ptr)->tp_name);
fflush(stderr);
} }
fprintf(stderr, "\n");
fflush(stderr);
throw std::runtime_error(function_name + " PyGILState_Check() failure."); throw std::runtime_error(function_name + " PyGILState_Check() failure.");
} }
#endif #endif

View File

@ -19,7 +19,7 @@ ignore = [
[tool.mypy] [tool.mypy]
files = ["pybind11"] files = ["pybind11"]
python_version = "3.6" python_version = "3.7"
strict = true strict = true
show_error_codes = true show_error_codes = true
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
@ -57,10 +57,13 @@ messages_control.disable = [
"unused-argument", # covered by Ruff ARG "unused-argument", # covered by Ruff ARG
] ]
[tool.ruff] [tool.ruff]
select = [ target-version = "py37"
"E", "F", "W", # flake8 src = ["src"]
line-length = 120
[tool.ruff.lint]
extend-select = [
"B", # flake8-bugbear "B", # flake8-bugbear
"I", # isort "I", # isort
"N", # pep8-naming "N", # pep8-naming
@ -86,13 +89,10 @@ ignore = [
"PT004", # Fixture that doesn't return needs underscore (no, it is fine) "PT004", # Fixture that doesn't return needs underscore (no, it is fine)
"SIM118", # iter(x) is not always the same as iter(x.keys()) "SIM118", # iter(x) is not always the same as iter(x.keys())
] ]
target-version = "py37"
src = ["src"]
unfixable = ["T20"] unfixable = ["T20"]
exclude = [] exclude = []
line-length = 120
isort.known-first-party = ["env", "pybind11_cross_module_tests", "pybind11_tests"] isort.known-first-party = ["env", "pybind11_cross_module_tests", "pybind11_tests"]
[tool.ruff.per-file-ignores] [tool.ruff.lint.per-file-ignores]
"tests/**" = ["EM", "N", "E721"] "tests/**" = ["EM", "N", "E721"]
"tests/test_call_policies.py" = ["PLC1901"] "tests/test_call_policies.py" = ["PLC1901"]

View File

@ -157,7 +157,7 @@ py::array mkarray_via_buffer(size_t n) {
do { \ do { \
(s).bool_ = (i) % 2 != 0; \ (s).bool_ = (i) % 2 != 0; \
(s).uint_ = (uint32_t) (i); \ (s).uint_ = (uint32_t) (i); \
(s).float_ = (float) (i) *1.5f; \ (s).float_ = (float) (i) * 1.5f; \
(s).ldbl_ = (long double) (i) * -2.5L; \ (s).ldbl_ = (long double) (i) * -2.5L; \
} while (0) } while (0)

View File

@ -662,8 +662,8 @@ TEST_SUBMODULE(pytypes, m) {
// This is "most correct" and enforced on these platforms. // This is "most correct" and enforced on these platforms.
# define PYBIND11_AUTO_IT auto it # define PYBIND11_AUTO_IT auto it
#else #else
// This works on many platforms and is (unfortunately) reflective of existing user code. // This works on many platforms and is (unfortunately) reflective of existing user code.
// NOLINTNEXTLINE(bugprone-macro-parentheses) // NOLINTNEXTLINE(bugprone-macro-parentheses)
# define PYBIND11_AUTO_IT auto &it # define PYBIND11_AUTO_IT auto &it
#endif #endif