@@ -241,9 +241,11 @@ the Python object to the required type.
241
241
242
242
For signed integer formats, :exc: `OverflowError ` is raised if the value
243
243
is out of range for the C type.
244
- For unsigned integer formats, no range checking is done --- the
244
+ For unsigned integer formats, the
245
245
most significant bits are silently truncated when the receiving field is too
246
- small to receive the value.
246
+ small to receive the value, and :exc: `DeprecationWarning ` is emitted when
247
+ the value is larger than the maximal value for the C type or less than
248
+ the minimal value for the corresponding signed integer type of the same size.
247
249
248
250
``b `` (:class: `int `) [unsigned char]
249
251
Convert a nonnegative Python integer to an unsigned tiny integer, stored in a C
@@ -252,27 +254,25 @@ small to receive the value.
252
254
``B `` (:class: `int `) [unsigned char]
253
255
Convert a Python integer to a tiny integer without overflow checking, stored in a C
254
256
:c:expr: `unsigned char `.
257
+ Convert a Python integer to a C :c:expr: `unsigned char `.
255
258
256
259
``h `` (:class: `int `) [short int]
257
260
Convert a Python integer to a C :c:expr: `short int `.
258
261
259
262
``H `` (:class: `int `) [unsigned short int]
260
- Convert a Python integer to a C :c:expr: `unsigned short int `, without overflow
261
- checking.
263
+ Convert a Python integer to a C :c:expr: `unsigned short int `.
262
264
263
265
``i `` (:class: `int `) [int]
264
266
Convert a Python integer to a plain C :c:expr: `int `.
265
267
266
268
``I `` (:class: `int `) [unsigned int]
267
- Convert a Python integer to a C :c:expr: `unsigned int `, without overflow
268
- checking.
269
+ Convert a Python integer to a C :c:expr: `unsigned int `.
269
270
270
271
``l `` (:class: `int `) [long int]
271
272
Convert a Python integer to a C :c:expr: `long int `.
272
273
273
274
``k `` (:class: `int `) [unsigned long]
274
- Convert a Python integer to a C :c:expr: `unsigned long ` without
275
- overflow checking.
275
+ Convert a Python integer to a C :c:expr: `unsigned long `.
276
276
277
277
.. versionchanged :: 3.14
278
278
Use :meth: `~object.__index__ ` if available.
@@ -281,8 +281,7 @@ small to receive the value.
281
281
Convert a Python integer to a C :c:expr: `long long `.
282
282
283
283
``K `` (:class: `int `) [unsigned long long]
284
- Convert a Python integer to a C :c:expr: `unsigned long long `
285
- without overflow checking.
284
+ Convert a Python integer to a C :c:expr: `unsigned long long `.
286
285
287
286
.. versionchanged :: 3.14
288
287
Use :meth: `~object.__index__ ` if available.
@@ -310,6 +309,14 @@ small to receive the value.
310
309
``D `` (:class: `complex `) [Py_complex]
311
310
Convert a Python complex number to a C :c:type: `Py_complex ` structure.
312
311
312
+ .. deprecated :: next
313
+
314
+ For unsigned integer formats ``B ``, ``H ``, ``I ``, ``k `` and ``K ``,
315
+ :exc: `DeprecationWarning ` is emitted when the value is larger than
316
+ the maximal value for the C type or less than the minimal value for
317
+ the corresponding signed integer type of the same size.
318
+
319
+
313
320
Other objects
314
321
-------------
315
322
@@ -686,6 +693,12 @@ Building values
686
693
``p`` (:class: `bool `) [int]
687
694
Convert a C :c:expr:`int` to a Python :class:`bool` object.
688
695
696
+ Be aware that this format requires an ``int`` argument.
697
+ Unlike most other contexts in C, variadic arguments are not coerced to
698
+ a suitable type automatically.
699
+ You can convert another type (for example, a pointer or a float) to a
700
+ suitable ``int`` value using ``(x) ? 1 : 0`` or ``!!x``.
701
+
689
702
.. versionadded:: 3.14
690
703
691
704
``c`` (:class: `bytes ` of length 1) [char]
0 commit comments