Skip to content

Commit 3feb1b1

Browse files
Merge branch 'main' into urllib-parse-allow-none
2 parents 2d98e4c + 5db331a commit 3feb1b1

File tree

13 files changed

+120
-50
lines changed

13 files changed

+120
-50
lines changed

Doc/c-api/long.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ Export API
687687
688688
.. versionadded:: 3.14
689689
690-
.. c:struct:: PyLongLayout
690+
.. c:type:: PyLongLayout
691691
692692
Layout of an array of "digits" ("limbs" in the GMP terminology), used to
693693
represent absolute value for arbitrary precision integers.
@@ -727,15 +727,15 @@ Export API
727727
728728
Get the native layout of Python :class:`int` objects.
729729
730-
See the :c:struct:`PyLongLayout` structure.
730+
See the :c:type:`PyLongLayout` structure.
731731
732732
The function must not be called before Python initialization nor after
733733
Python finalization. The returned layout is valid until Python is
734734
finalized. The layout is the same for all Python sub-interpreters
735735
in a process, and so it can be cached.
736736
737737
738-
.. c:struct:: PyLongExport
738+
.. c:type:: PyLongExport
739739
740740
Export of a Python :class:`int` object.
741741
@@ -769,7 +769,7 @@ Export API
769769
770770
Export a Python :class:`int` object.
771771
772-
*export_long* must point to a :c:struct:`PyLongExport` structure allocated
772+
*export_long* must point to a :c:type:`PyLongExport` structure allocated
773773
by the caller. It must not be ``NULL``.
774774
775775
On success, fill in *\*export_long* and return ``0``.
@@ -799,7 +799,7 @@ The :c:type:`PyLongWriter` API can be used to import an integer.
799799
800800
.. versionadded:: 3.14
801801
802-
.. c:struct:: PyLongWriter
802+
.. c:type:: PyLongWriter
803803
804804
A Python :class:`int` writer instance.
805805
@@ -827,7 +827,7 @@ The :c:type:`PyLongWriter` API can be used to import an integer.
827827
The layout of *digits* is described by :c:func:`PyLong_GetNativeLayout`.
828828
829829
Digits must be in the range [``0``; ``(1 << bits_per_digit) - 1``]
830-
(where the :c:struct:`~PyLongLayout.bits_per_digit` is the number of bits
830+
(where the :c:type:`~PyLongLayout.bits_per_digit` is the number of bits
831831
per digit).
832832
Any unused most significant digits must be set to ``0``.
833833

Doc/data/stable_abi.dat

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/cpython/longintrepr.h

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -138,45 +138,6 @@ _PyLong_CompactValue(const PyLongObject *op)
138138

139139
#define PyUnstable_Long_CompactValue _PyLong_CompactValue
140140

141-
142-
/* --- Import/Export API -------------------------------------------------- */
143-
144-
typedef struct PyLongLayout {
145-
uint8_t bits_per_digit;
146-
uint8_t digit_size;
147-
int8_t digits_order;
148-
int8_t digit_endianness;
149-
} PyLongLayout;
150-
151-
PyAPI_FUNC(const PyLongLayout*) PyLong_GetNativeLayout(void);
152-
153-
typedef struct PyLongExport {
154-
int64_t value;
155-
uint8_t negative;
156-
Py_ssize_t ndigits;
157-
const void *digits;
158-
// Member used internally, must not be used for other purpose.
159-
Py_uintptr_t _reserved;
160-
} PyLongExport;
161-
162-
PyAPI_FUNC(int) PyLong_Export(
163-
PyObject *obj,
164-
PyLongExport *export_long);
165-
PyAPI_FUNC(void) PyLong_FreeExport(
166-
PyLongExport *export_long);
167-
168-
169-
/* --- PyLongWriter API --------------------------------------------------- */
170-
171-
typedef struct PyLongWriter PyLongWriter;
172-
173-
PyAPI_FUNC(PyLongWriter*) PyLongWriter_Create(
174-
int negative,
175-
Py_ssize_t ndigits,
176-
void **digits);
177-
PyAPI_FUNC(PyObject*) PyLongWriter_Finish(PyLongWriter *writer);
178-
PyAPI_FUNC(void) PyLongWriter_Discard(PyLongWriter *writer);
179-
180141
#ifdef __cplusplus
181142
}
182143
#endif

Include/longobject.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,44 @@ PyAPI_FUNC(PyObject *) PyLong_FromString(const char *, char **, int);
166166
PyAPI_FUNC(unsigned long) PyOS_strtoul(const char *, char **, int);
167167
PyAPI_FUNC(long) PyOS_strtol(const char *, char **, int);
168168

169+
/* --- Import/Export API -------------------------------------------------- */
170+
171+
typedef struct PyLongLayout {
172+
uint8_t bits_per_digit;
173+
uint8_t digit_size;
174+
int8_t digits_order;
175+
int8_t digit_endianness;
176+
} PyLongLayout;
177+
178+
PyAPI_FUNC(const PyLongLayout*) PyLong_GetNativeLayout(void);
179+
180+
typedef struct PyLongExport {
181+
int64_t value;
182+
uint8_t negative;
183+
Py_ssize_t ndigits;
184+
const void *digits;
185+
// Member used internally, must not be used for other purpose.
186+
Py_uintptr_t _reserved;
187+
} PyLongExport;
188+
189+
PyAPI_FUNC(int) PyLong_Export(
190+
PyObject *obj,
191+
PyLongExport *export_long);
192+
PyAPI_FUNC(void) PyLong_FreeExport(
193+
PyLongExport *export_long);
194+
195+
196+
/* --- PyLongWriter API --------------------------------------------------- */
197+
198+
typedef struct PyLongWriter PyLongWriter;
199+
200+
PyAPI_FUNC(PyLongWriter*) PyLongWriter_Create(
201+
int negative,
202+
Py_ssize_t ndigits,
203+
void **digits);
204+
PyAPI_FUNC(PyObject*) PyLongWriter_Finish(PyLongWriter *writer);
205+
PyAPI_FUNC(void) PyLongWriter_Discard(PyLongWriter *writer);
206+
169207
#ifndef Py_LIMITED_API
170208
# define Py_CPYTHON_LONGOBJECT_H
171209
# include "cpython/longobject.h"

Lib/functools.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,9 @@ def decorating_function(user_function):
602602
return decorating_function
603603

604604
def _lru_cache_wrapper(user_function, maxsize, typed, _CacheInfo):
605+
if not callable(user_function):
606+
raise TypeError("the first argument must be callable")
607+
605608
# Constants shared by all lru cache instances:
606609
sentinel = object() # unique object used to signal cache misses
607610
make_key = _make_key # build a key from the function arguments

Lib/inspect.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ def isgenerator(object):
348348
gi_frame frame object or possibly None once the generator has
349349
been exhausted
350350
gi_running set to 1 when generator is executing, 0 otherwise
351+
gi_suspended set to 1 when the generator is suspended at a yield point, 0 otherwise
351352
gi_yieldfrom object being iterated by yield from or None
352353
353354
__iter__() defined to support iteration over container

Lib/test/test_functools.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,6 +2157,13 @@ def fib(n):
21572157
with self.assertRaises(RecursionError):
21582158
fib(support.exceeds_recursion_limit())
21592159

2160+
def test_lru_checks_arg_is_callable(self):
2161+
with self.assertRaisesRegex(
2162+
TypeError,
2163+
"the first argument must be callable",
2164+
):
2165+
self.module.lru_cache(1)('hello')
2166+
21602167

21612168
@py_functools.lru_cache()
21622169
def py_cached_func(x, y):

Lib/test/test_stable_abi_ctypes.py

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/test/test_types.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,8 +2294,8 @@ def foo(): return gen
22942294
self.assertIs(wrapper.__name__, gen.__name__)
22952295

22962296
# Test AttributeErrors
2297-
for name in {'gi_running', 'gi_frame', 'gi_code', 'gi_yieldfrom',
2298-
'cr_running', 'cr_frame', 'cr_code', 'cr_await'}:
2297+
for name in {'gi_running', 'gi_frame', 'gi_code', 'gi_yieldfrom', 'gi_suspended',
2298+
'cr_running', 'cr_frame', 'cr_code', 'cr_await', 'cr_suspended'}:
22992299
with self.assertRaises(AttributeError):
23002300
getattr(wrapper, name)
23012301

@@ -2304,14 +2304,17 @@ def foo(): return gen
23042304
gen.gi_frame = object()
23052305
gen.gi_code = object()
23062306
gen.gi_yieldfrom = object()
2307+
gen.gi_suspended = object()
23072308
self.assertIs(wrapper.gi_running, gen.gi_running)
23082309
self.assertIs(wrapper.gi_frame, gen.gi_frame)
23092310
self.assertIs(wrapper.gi_code, gen.gi_code)
23102311
self.assertIs(wrapper.gi_yieldfrom, gen.gi_yieldfrom)
2312+
self.assertIs(wrapper.gi_suspended, gen.gi_suspended)
23112313
self.assertIs(wrapper.cr_running, gen.gi_running)
23122314
self.assertIs(wrapper.cr_frame, gen.gi_frame)
23132315
self.assertIs(wrapper.cr_code, gen.gi_code)
23142316
self.assertIs(wrapper.cr_await, gen.gi_yieldfrom)
2317+
self.assertIs(wrapper.cr_suspended, gen.gi_suspended)
23152318

23162319
wrapper.close()
23172320
gen.close.assert_called_once_with()
@@ -2430,7 +2433,7 @@ def foo(): return gen
24302433
self.assertIs(wrapper.__await__(), gen)
24312434

24322435
for name in ('__name__', '__qualname__', 'gi_code',
2433-
'gi_running', 'gi_frame'):
2436+
'gi_running', 'gi_frame', 'gi_suspended'):
24342437
self.assertIs(getattr(foo(), name),
24352438
getattr(gen, name))
24362439
self.assertIs(foo().cr_code, gen.gi_code)
@@ -2493,8 +2496,8 @@ def coro():
24932496
self.assertEqual(repr(wrapper), str(wrapper))
24942497
self.assertTrue(set(dir(wrapper)).issuperset({
24952498
'__await__', '__iter__', '__next__', 'cr_code', 'cr_running',
2496-
'cr_frame', 'gi_code', 'gi_frame', 'gi_running', 'send',
2497-
'close', 'throw'}))
2499+
'cr_frame', 'cr_suspended', 'gi_code', 'gi_frame', 'gi_running',
2500+
'gi_suspended', 'send', 'close', 'throw'}))
24982501

24992502

25002503
class FunctionTests(unittest.TestCase):
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Added :c:func:`PyLong_GetNativeLayout`, :c:struct:`PyLongLayout`,
2+
:c:struct:`PyLongExport`, :c:func:`PyLong_Export`,
3+
:c:func:`PyLong_FreeExport`, :c:struct:`PyLongWriter`,
4+
:c:func:`PyLongWriter_Create`, :c:func:`PyLongWriter_Finish` and
5+
:c:func:`PyLongWriter_Discard` to the limited API.

0 commit comments

Comments
 (0)