Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ Mutable sequence types also support the following methods:
:no-typesetting:
.. method:: sequence.append(value, /)

Append *value* to the end of the sequence
Append *value* to the end of the sequence.
This is equivalent to writing ``seq[len(seq):len(seq)] = [value]``.

.. method:: bytearray.clear()
Expand Down
8 changes: 6 additions & 2 deletions Lib/asyncio/base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
import errno
import heapq
import itertools
import math
import os
import socket
import stat
import subprocess
import sys
import threading
import time
import traceback
import sys
import warnings
import weakref

Expand Down Expand Up @@ -2022,7 +2023,10 @@ def _run_once(self):
event_list = None

# Handle 'later' callbacks that are ready.
end_time = self.time() + self._clock_resolution
now = self.time()
# Ensure that `end_time` is strictly increasing
# when the clock resolution is too small.
end_time = now + max(self._clock_resolution, math.ulp(now))
while self._scheduled:
handle = self._scheduled[0]
if handle._when >= end_time:
Expand Down
15 changes: 15 additions & 0 deletions Lib/test/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2168,6 +2168,21 @@ class Spam(types.SimpleNamespace):
self.assertIs(type(spam2), Spam)
self.assertEqual(vars(spam2), {'ham': 5, 'eggs': 9})

def test_replace_invalid_subtype(self):
# See https://github.com/python/cpython/issues/143636.
class MyNS(types.SimpleNamespace):
def __new__(cls, *args, **kwargs):
if created:
return 12345
return super().__new__(cls)

created = False
ns = MyNS()
created = True
err = (r"^expect types\.SimpleNamespace type, "
r"but .+\.MyNS\(\) returned 'int' object")
self.assertRaisesRegex(TypeError, err, copy.replace, ns)

def test_fake_namespace_compare(self):
# Issue #24257: Incorrect use of PyObject_IsInstance() caused
# SystemError.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a crash when calling :class:`SimpleNamespace.__replace__()
<types.SimpleNamespace>` on non-namespace instances. Patch by Bénédikt Tran.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:mod:`asyncio`: Make sure that :meth:`loop.call_at <asyncio.loop.call_at>` and
:meth:`loop.call_later <asyncio.loop.call_later>` trigger scheduled events on
time when the clock resolution becomes too small.
9 changes: 9 additions & 0 deletions Objects/namespaceobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ typedef struct {
} _PyNamespaceObject;

#define _PyNamespace_CAST(op) _Py_CAST(_PyNamespaceObject*, (op))
#define _PyNamespace_Check(op) PyObject_TypeCheck((op), &_PyNamespace_Type)


static PyMemberDef namespace_members[] = {
Expand Down Expand Up @@ -234,6 +235,14 @@ namespace_replace(PyObject *self, PyObject *args, PyObject *kwargs)
if (!result) {
return NULL;
}
if (!_PyNamespace_Check(result)) {
PyErr_Format(PyExc_TypeError,
"expect %N type, but %T() returned '%T' object",
&_PyNamespace_Type, self, result);
Py_DECREF(result);
return NULL;
}

if (PyDict_Update(((_PyNamespaceObject*)result)->ns_dict,
((_PyNamespaceObject*)self)->ns_dict) < 0)
{
Expand Down
Loading