Skip to content

Commit c31124f

Browse files
Merge branch 'master' into import-refcounts
2 parents 03e405f + 4ac923f commit c31124f

16 files changed

+243
-57
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- name: Check for source changes
2929
id: check
3030
run: |
31-
if [ -z "GITHUB_BASE_REF" ]; then
31+
if [ -z "$GITHUB_BASE_REF" ]; then
3232
echo '::set-output name=run_tests::true'
3333
else
3434
git fetch origin $GITHUB_BASE_REF --depth=1

Doc/howto/descriptor.rst

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -934,32 +934,42 @@ here is a pure Python equivalent:
934934
if doc is None and fget is not None:
935935
doc = fget.__doc__
936936
self.__doc__ = doc
937+
self._name = ''
938+
939+
def __set_name__(self, owner, name):
940+
self._name = name
937941

938942
def __get__(self, obj, objtype=None):
939943
if obj is None:
940944
return self
941945
if self.fget is None:
942-
raise AttributeError("unreadable attribute")
946+
raise AttributeError(f'unreadable attribute {self._name}')
943947
return self.fget(obj)
944948

945949
def __set__(self, obj, value):
946950
if self.fset is None:
947-
raise AttributeError("can't set attribute")
951+
raise AttributeError(f"can't set attribute {self._name}")
948952
self.fset(obj, value)
949953

950954
def __delete__(self, obj):
951955
if self.fdel is None:
952-
raise AttributeError("can't delete attribute")
956+
raise AttributeError(f"can't delete attribute {self._name}")
953957
self.fdel(obj)
954958

955959
def getter(self, fget):
956-
return type(self)(fget, self.fset, self.fdel, self.__doc__)
960+
prop = type(self)(fget, self.fset, self.fdel, self.__doc__)
961+
prop._name = self._name
962+
return prop
957963

958964
def setter(self, fset):
959-
return type(self)(self.fget, fset, self.fdel, self.__doc__)
965+
prop = type(self)(self.fget, fset, self.fdel, self.__doc__)
966+
prop._name = self._name
967+
return prop
960968

961969
def deleter(self, fdel):
962-
return type(self)(self.fget, self.fset, fdel, self.__doc__)
970+
prop = type(self)(self.fget, self.fset, fdel, self.__doc__)
971+
prop._name = self._name
972+
return prop
963973

964974
.. testcode::
965975
:hide:

Doc/whatsnew/3.10.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,10 @@ Build Changes
558558
* The :mod:`atexit` module must now always be built as a built-in module.
559559
(Contributed by Victor Stinner in :issue:`42639`.)
560560

561+
* Added ``--disable-test-modules`` option to the ``configure`` script:
562+
don't build nor install test modules.
563+
(Contributed by Xavier de Gaye, Thomas Petazzoni and Peixing Xin in :issue:`27640`.)
564+
561565

562566
C API Changes
563567
=============

Include/cpython/abstract.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ PyVectorcall_Function(PyObject *callable)
6363
{
6464
PyTypeObject *tp;
6565
Py_ssize_t offset;
66-
vectorcallfunc *ptr;
66+
vectorcallfunc ptr;
6767

6868
assert(callable != NULL);
6969
tp = Py_TYPE(callable);
@@ -73,8 +73,8 @@ PyVectorcall_Function(PyObject *callable)
7373
assert(PyCallable_Check(callable));
7474
offset = tp->tp_vectorcall_offset;
7575
assert(offset > 0);
76-
ptr = (vectorcallfunc *)(((char *)callable) + offset);
77-
return *ptr;
76+
memcpy(&ptr, (char *) callable + offset, sizeof(ptr));
77+
return ptr;
7878
}
7979

8080
/* Call the callable object 'callable' with the "vectorcall" calling

Lib/test/test_property.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,16 @@ def __doc__(cls):
204204
return 'Second'
205205
self.assertEqual(A.__doc__, 'Second')
206206

207+
def test_property_set_name_incorrect_args(self):
208+
p = property()
209+
210+
for i in (0, 1, 3):
211+
with self.assertRaisesRegex(
212+
TypeError,
213+
fr'^__set_name__\(\) takes 2 positional arguments but {i} were given$'
214+
):
215+
p.__set_name__(*([0] * i))
216+
207217

208218
# Issue 5890: subclasses of property do not preserve method __doc__ strings
209219
class PropertySub(property):
@@ -299,6 +309,46 @@ def spam(self):
299309
self.assertEqual(Foo.spam.__doc__, "a new docstring")
300310

301311

312+
class _PropertyUnreachableAttribute:
313+
msg_format = None
314+
obj = None
315+
cls = None
316+
317+
def _format_exc_msg(self, msg):
318+
return self.msg_format.format(msg)
319+
320+
@classmethod
321+
def setUpClass(cls):
322+
cls.obj = cls.cls()
323+
324+
def test_get_property(self):
325+
with self.assertRaisesRegex(AttributeError, self._format_exc_msg("unreadable attribute")):
326+
self.obj.foo
327+
328+
def test_set_property(self):
329+
with self.assertRaisesRegex(AttributeError, self._format_exc_msg("can't set attribute")):
330+
self.obj.foo = None
331+
332+
def test_del_property(self):
333+
with self.assertRaisesRegex(AttributeError, self._format_exc_msg("can't delete attribute")):
334+
del self.obj.foo
335+
336+
337+
class PropertyUnreachableAttributeWithName(_PropertyUnreachableAttribute, unittest.TestCase):
338+
msg_format = "^{} 'foo'$"
339+
340+
class cls:
341+
foo = property()
342+
343+
344+
class PropertyUnreachableAttributeNoName(_PropertyUnreachableAttribute, unittest.TestCase):
345+
msg_format = "^{}$"
346+
347+
class cls:
348+
pass
349+
350+
cls.foo = property()
351+
302352

303353
if __name__ == '__main__':
304354
unittest.main()

Lib/test/test_sys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,7 @@ def getx(self): return self.__x
13291329
def setx(self, value): self.__x = value
13301330
def delx(self): del self.__x
13311331
x = property(getx, setx, delx, "")
1332-
check(x, size('4Pi'))
1332+
check(x, size('5Pi'))
13331333
# PyCapsule
13341334
# XXX
13351335
# rangeiterator

Makefile.pre.in

Lines changed: 71 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,27 +1366,61 @@ maninstall: altmaninstall
13661366

13671367
# Install the library
13681368
XMLLIBSUBDIRS= xml xml/dom xml/etree xml/parsers xml/sax
1369-
LIBSUBDIRS= tkinter tkinter/test tkinter/test/test_tkinter \
1370-
tkinter/test/test_ttk site-packages test \
1371-
test/audiodata \
1372-
test/capath test/data \
1373-
test/cjkencodings test/decimaltestdata \
1374-
test/xmltestdata test/xmltestdata/c14n-20 \
1375-
test/dtracedata \
1376-
test/eintrdata \
1377-
test/imghdrdata \
1378-
test/libregrtest \
1379-
test/subprocessdata test/sndhdrdata test/support \
1380-
test/tracedmodules test/encoded_modules \
1369+
LIBSUBDIRS= asyncio \
1370+
collections \
1371+
concurrent concurrent/futures \
1372+
csv \
1373+
ctypes ctypes/macholib \
1374+
curses \
1375+
dbm \
1376+
distutils distutils/command \
1377+
email email/mime \
1378+
encodings \
1379+
ensurepip ensurepip/_bundled \
1380+
html \
1381+
http \
1382+
idlelib idlelib/Icons \
1383+
importlib importlib/metadata \
1384+
json \
1385+
lib2to3 lib2to3/fixes lib2to3/pgen2 \
1386+
logging \
1387+
multiprocessing multiprocessing/dummy \
1388+
pydoc_data \
1389+
site-packages \
1390+
sqlite3 \
1391+
tkinter \
1392+
turtledemo \
1393+
unittest \
1394+
urllib \
1395+
venv venv/scripts venv/scripts/common venv/scripts/posix \
1396+
wsgiref \
1397+
$(XMLLIBSUBDIRS) \
1398+
xmlrpc \
1399+
zoneinfo
1400+
TESTSUBDIRS= ctypes/test \
1401+
distutils/tests \
1402+
idlelib/idle_test \
1403+
lib2to3/tests \
1404+
lib2to3/tests/data \
1405+
lib2to3/tests/data/fixers \
1406+
lib2to3/tests/data/fixers/myfixes \
1407+
sqlite3/test \
1408+
test test/audiodata \
1409+
test/capath test/cjkencodings \
1410+
test/data test/decimaltestdata \
1411+
test/dtracedata test/eintrdata \
1412+
test/encoded_modules test/imghdrdata \
1413+
test/libregrtest test/sndhdrdata \
1414+
test/subprocessdata test/support \
1415+
test/test_asyncio \
1416+
test/test_email test/test_email/data \
13811417
test/test_import \
13821418
test/test_import/data \
13831419
test/test_import/data/circular_imports \
13841420
test/test_import/data/circular_imports/subpkg \
13851421
test/test_import/data/package \
13861422
test/test_import/data/package2 \
13871423
test/test_import/data/unwritable \
1388-
importlib \
1389-
importlib/metadata \
13901424
test/test_importlib \
13911425
test/test_importlib/builtin \
13921426
test/test_importlib/data \
@@ -1425,30 +1459,19 @@ LIBSUBDIRS= tkinter tkinter/test tkinter/test/test_tkinter \
14251459
test/test_importlib/source \
14261460
test/test_importlib/zipdata01 \
14271461
test/test_importlib/zipdata02 \
1462+
test/test_json \
1463+
test/test_peg_generator \
1464+
test/test_tools \
1465+
test/test_warnings test/test_warnings/data \
14281466
test/test_zoneinfo test/test_zoneinfo/data \
1467+
test/tracedmodules \
1468+
test/xmltestdata test/xmltestdata/c14n-20 \
14291469
test/ziptestdata \
1430-
asyncio \
1431-
test/test_asyncio \
1432-
collections concurrent concurrent/futures encodings \
1433-
email email/mime test/test_email test/test_email/data \
1434-
ensurepip ensurepip/_bundled \
1435-
html json test/test_json http dbm xmlrpc \
1436-
sqlite3 sqlite3/test \
1437-
logging csv wsgiref urllib \
1438-
lib2to3 lib2to3/fixes lib2to3/pgen2 lib2to3/tests \
1439-
lib2to3/tests/data lib2to3/tests/data/fixers \
1440-
lib2to3/tests/data/fixers/myfixes \
1441-
ctypes ctypes/test ctypes/macholib \
1442-
idlelib idlelib/Icons idlelib/idle_test \
1443-
distutils distutils/command distutils/tests $(XMLLIBSUBDIRS) \
1444-
test/test_peg_generator \
1445-
test/test_tools test/test_warnings test/test_warnings/data \
1446-
turtledemo \
1447-
multiprocessing multiprocessing/dummy \
1448-
unittest unittest/test unittest/test/testmock \
1449-
venv venv/scripts venv/scripts/common venv/scripts/posix \
1450-
curses pydoc_data \
1451-
zoneinfo
1470+
tkinter/test tkinter/test/test_tkinter \
1471+
tkinter/test/test_ttk \
1472+
unittest/test unittest/test/testmock
1473+
1474+
TEST_MODULES=@TEST_MODULES@
14521475
libinstall: build_all $(srcdir)/Modules/xxmodule.c
14531476
@for i in $(SCRIPTDIR) $(LIBDEST); \
14541477
do \
@@ -1458,7 +1481,12 @@ libinstall: build_all $(srcdir)/Modules/xxmodule.c
14581481
else true; \
14591482
fi; \
14601483
done
1461-
@for d in $(LIBSUBDIRS); \
1484+
@if test "$(TEST_MODULES)" = yes; then \
1485+
subdirs="$(LIBSUBDIRS) $(TESTSUBDIRS)"; \
1486+
else \
1487+
subdirs="$(LIBSUBDIRS)"; \
1488+
fi; \
1489+
for d in $$subdirs; \
14621490
do \
14631491
a=$(srcdir)/Lib/$$d; \
14641492
if test ! -d $$a; then continue; else true; fi; \
@@ -1479,7 +1507,12 @@ libinstall: build_all $(srcdir)/Modules/xxmodule.c
14791507
echo $(INSTALL_DATA) $$i $(LIBDEST); \
14801508
fi; \
14811509
done
1482-
@for d in $(LIBSUBDIRS); \
1510+
@if test "$(TEST_MODULES)" = yes; then \
1511+
subdirs="$(LIBSUBDIRS) $(TESTSUBDIRS)"; \
1512+
else \
1513+
subdirs="$(LIBSUBDIRS)"; \
1514+
fi; \
1515+
for d in $$subdirs; \
14831516
do \
14841517
a=$(srcdir)/Lib/$$d; \
14851518
if test ! -d $$a; then continue; else true; fi; \
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Added ``--disable-test-modules`` option to the ``configure`` script:
2+
don't build nor install test modules.
3+
Patch by Xavier de Gaye, Thomas Petazzoni and Peixing Xin.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix an alignment build warning/error in function ``PyVectorcall_Function()``.
2+
Patch by Andreas Schneider, Antoine Pitrou and Petr Viktorin.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Improve the error message for failed writes/deletes to property objects.
2+
When possible, the attribute name is now shown. Patch provided by
3+
Yurii Karabas.

Modules/_functoolsmodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,7 @@ _functools_exec(PyObject *module)
14361436
Py_DECREF(lru_cache_type);
14371437
return -1;
14381438
}
1439+
Py_DECREF(lru_cache_type);
14391440

14401441
state->keyobject_type = (PyTypeObject *)PyType_FromModuleAndSpec(module,
14411442
&keyobject_type_spec, NULL);

Objects/call.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ PyObject *
205205
PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *kwargs)
206206
{
207207
PyThreadState *tstate = _PyThreadState_GET();
208+
vectorcallfunc func;
208209

209210
/* get vectorcallfunc as in PyVectorcall_Function, but without
210211
* the Py_TPFLAGS_HAVE_VECTORCALL check */
@@ -215,7 +216,7 @@ PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *kwargs)
215216
Py_TYPE(callable)->tp_name);
216217
return NULL;
217218
}
218-
vectorcallfunc func = *(vectorcallfunc *)(((char *)callable) + offset);
219+
memcpy(&func, (char *) callable + offset, sizeof(func));
219220
if (func == NULL) {
220221
_PyErr_Format(tstate, PyExc_TypeError,
221222
"'%.200s' object does not support vectorcall",

0 commit comments

Comments
 (0)