Skip to content

Commit 4880140

Browse files
committed
Merge branch 'master' into smart_holder
2 parents 3108eb9 + f676782 commit 4880140

File tree

6 files changed

+32
-10
lines changed

6 files changed

+32
-10
lines changed

docs/advanced/classes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ override the ``name()`` method):
259259
260260
.. note::
261261

262-
Note the trailing commas in the ``PYBIND11_OVERIDE`` calls to ``name()``
262+
Note the trailing commas in the ``PYBIND11_OVERRIDE`` calls to ``name()``
263263
and ``bark()``. These are needed to portably implement a trampoline for a
264264
function that does not take any arguments. For functions that take
265265
a nonzero number of arguments, the trailing comma must be omitted.

include/pybind11/pybind11.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,8 @@ class cpp_function : public function {
525525

526526
auto self_value_and_holder = value_and_holder();
527527
if (overloads->is_constructor) {
528-
if (!PyObject_TypeCheck(parent.ptr(), (PyTypeObject *) overloads->scope.ptr())) {
529-
PyErr_SetString(PyExc_TypeError, "__init__(self, ...) called with invalid `self` argument");
528+
if (!parent || !PyObject_TypeCheck(parent.ptr(), (PyTypeObject *) overloads->scope.ptr())) {
529+
PyErr_SetString(PyExc_TypeError, "__init__(self, ...) called with invalid or missing `self` argument");
530530
return nullptr;
531531
}
532532

pybind11/setup_helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import threading
4848
import platform
4949
import warnings
50+
import sysconfig
5051

5152
try:
5253
from setuptools.command.build_ext import build_ext as _build_ext
@@ -59,7 +60,7 @@
5960
import distutils.ccompiler
6061

6162

62-
WIN = sys.platform.startswith("win32")
63+
WIN = sys.platform.startswith("win32") and sysconfig.get_platform() != "mingw"
6364
PY2 = sys.version_info[0] < 3
6465
MACOS = sys.platform.startswith("darwin")
6566
STD_TMPL = "/std:c++{}" if WIN else "-std=c++{}"

tests/env.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import platform
33
import sys
44

5+
import pytest
6+
57
LINUX = sys.platform.startswith("linux")
68
MACOS = sys.platform.startswith("darwin")
79
WIN = sys.platform.startswith("win32") or sys.platform.startswith("cygwin")
@@ -12,3 +14,20 @@
1214
PY2 = sys.version_info.major == 2
1315

1416
PY = sys.version_info
17+
18+
19+
def deprecated_call():
20+
"""
21+
pytest.deprecated_call() seems broken in pytest<3.9.x; concretely, it
22+
doesn't work on CPython 3.8.0 with pytest==3.3.2 on Ubuntu 18.04 (#2922).
23+
24+
This is a narrowed reimplementation of the following PR :(
25+
https://github.com/pytest-dev/pytest/pull/4104
26+
"""
27+
# TODO: Remove this when testing requires pytest>=3.9.
28+
pieces = pytest.__version__.split(".")
29+
pytest_major_minor = (int(pieces[0]), int(pieces[1]))
30+
if pytest_major_minor < (3, 9):
31+
return pytest.warns((DeprecationWarning, PendingDeprecationWarning))
32+
else:
33+
return pytest.deprecated_call()

tests/test_builtin_casters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def cant_convert(v):
301301
cant_convert(3.14159)
302302
# TODO: Avoid DeprecationWarning in `PyLong_AsLong` (and similar)
303303
if (3, 8) <= env.PY < (3, 10):
304-
with pytest.deprecated_call():
304+
with env.deprecated_call():
305305
assert convert(Int()) == 42
306306
else:
307307
assert convert(Int()) == 42
@@ -336,7 +336,7 @@ def require_implicit(v):
336336
# The implicit conversion from np.float32 is undesirable but currently accepted.
337337
# TODO: Avoid DeprecationWarning in `PyLong_AsLong` (and similar)
338338
if (3, 8) <= env.PY < (3, 10):
339-
with pytest.deprecated_call():
339+
with env.deprecated_call():
340340
assert convert(np.float32(3.14159)) == 3
341341
else:
342342
assert convert(np.float32(3.14159)) == 3

tests/test_factory_constructors.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,9 @@ def __init__(self, bad):
486486
# Same as above, but for a class with an alias:
487487
class BrokenTF6(m.TestFactory6):
488488
def __init__(self, bad):
489-
if bad == 1:
489+
if bad == 0:
490+
m.TestFactory6.__init__()
491+
elif bad == 1:
490492
a = m.TestFactory2(tag.pointer, 1)
491493
m.TestFactory6.__init__(a, tag.base, 1)
492494
elif bad == 2:
@@ -506,13 +508,13 @@ def __init__(self, bad):
506508
BrokenTF1(arg)
507509
assert (
508510
str(excinfo.value)
509-
== "__init__(self, ...) called with invalid `self` argument"
511+
== "__init__(self, ...) called with invalid or missing `self` argument"
510512
)
511513

512-
for arg in (1, 2, 3, 4):
514+
for arg in (0, 1, 2, 3, 4):
513515
with pytest.raises(TypeError) as excinfo:
514516
BrokenTF6(arg)
515517
assert (
516518
str(excinfo.value)
517-
== "__init__(self, ...) called with invalid `self` argument"
519+
== "__init__(self, ...) called with invalid or missing `self` argument"
518520
)

0 commit comments

Comments
 (0)