Skip to content

Commit d43ba9d

Browse files
committed
Merge in the main branch
2 parents 5a3f808 + 1e21cf6 commit d43ba9d

38 files changed

Lines changed: 978 additions & 384 deletions

Doc/data/stable_abi.dat

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

Doc/library/array.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ defined:
5252
+-----------+--------------------+-------------------+-----------------------+-------+
5353
| ``'D'`` | double complex | complex | 16 | \(4) |
5454
+-----------+--------------------+-------------------+-----------------------+-------+
55+
| ``'Zf'`` | float complex | complex | 8 | \(4) |
56+
+-----------+--------------------+-------------------+-----------------------+-------+
57+
| ``'Zd'`` | double complex | complex | 16 | \(4) |
58+
+-----------+--------------------+-------------------+-----------------------+-------+
5559

5660

5761
Notes:
@@ -80,7 +84,7 @@ Notes:
8084
.. versionadded:: 3.15
8185

8286
(4)
83-
Complex types (``F`` and ``D``) are available unconditionally,
87+
Complex types (``F``, ``D``, ``Zf`` and ``Zd``) are available unconditionally,
8488
regardless on support for complex types (the Annex G of the C11 standard)
8589
by the C compiler.
8690
As specified in the C11 standard, each complex type is represented by a
@@ -105,7 +109,10 @@ The module defines the following item:
105109

106110
.. data:: typecodes
107111

108-
A string with all available type codes.
112+
A tuple with all available type codes.
113+
114+
.. versionchanged:: next
115+
The type changed from :class:`str` to :class:`tuple`.
109116

110117

111118
The module defines the following type:

Doc/library/ctypes.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,15 +370,19 @@ in both C and ``libffi``, the following complex types are available:
370370
* - :class:`c_float_complex`
371371
- :c:expr:`float complex`
372372
- :py:class:`complex`
373-
- ``'F'``
373+
- ``'Zf'``
374374
* - :class:`c_double_complex`
375375
- :c:expr:`double complex`
376376
- :py:class:`complex`
377-
- ``'D'``
377+
- ``'Zd'``
378378
* - :class:`c_longdouble_complex`
379379
- :c:expr:`long double complex`
380380
- :py:class:`complex`
381-
- ``'G'``
381+
- ``'Zg'``
382+
383+
.. versionchanged:: next
384+
The :py:attr:`~_SimpleCData._type_` types ``F``, ``D`` and ``G`` have been
385+
replaced with ``Zf``, ``Zd`` and ``Zg``.
382386

383387

384388
All these types can be created by calling them with an optional initializer of

Doc/library/inspect.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1833,8 +1833,15 @@ from the command line.
18331833

18341834
By default, accepts the name of a module and prints the source of that
18351835
module. A class or function within the module can be printed instead by
1836-
appended a colon and the qualified name of the target object.
1836+
appending a colon and the qualified name of the target object.
18371837

18381838
.. option:: --details
18391839

18401840
Print information about the specified object rather than the source code
1841+
1842+
.. versionchanged:: next
1843+
1844+
The ``--details`` option now supports basic introspection for modules
1845+
without available source code and indicates when modules are frozen.
1846+
It also indicates when the given target reference is not the canonical
1847+
name of the referenced object.

Doc/library/struct.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ platform-dependent.
264264
+--------+--------------------------+--------------------+----------------+------------+
265265
| ``D`` | :c:expr:`double complex` | complex | 16 | \(10) |
266266
+--------+--------------------------+--------------------+----------------+------------+
267+
| ``Zf`` | :c:expr:`float complex` | complex | 8 | \(10) |
268+
+--------+--------------------------+--------------------+----------------+------------+
269+
| ``Zd`` | :c:expr:`double complex` | complex | 16 | \(10) |
270+
+--------+--------------------------+--------------------+----------------+------------+
267271
| ``s`` | :c:expr:`char[]` | bytes | | \(9) |
268272
+--------+--------------------------+--------------------+----------------+------------+
269273
| ``p`` | :c:expr:`char[]` | bytes | | \(8) |
@@ -280,6 +284,9 @@ platform-dependent.
280284
.. versionchanged:: 3.14
281285
Added support for the ``'F'`` and ``'D'`` formats.
282286

287+
.. versionchanged:: next
288+
Added support for the ``'Zf'`` and ``'Zd'`` formats.
289+
283290
.. seealso::
284291

285292
The :mod:`array` and :ref:`ctypes <ctypes-fundamental-data-types>` modules,
@@ -372,7 +379,7 @@ Notes:
372379
For the ``'F'`` and ``'D'`` format characters, the packed representation uses
373380
the IEEE 754 binary32 and binary64 format for components of the complex
374381
number, regardless of the floating-point format used by the platform.
375-
Note that complex types (``F`` and ``D``) are available unconditionally,
382+
Note that complex types (``F``/``Zf`` and ``D``/``Zd``) are available unconditionally,
376383
despite complex types being an optional feature in C.
377384
As specified in the C11 standard, each complex type is represented by a
378385
two-element C array containing, respectively, the real and imaginary parts.

Doc/whatsnew/3.15.rst

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -704,9 +704,9 @@ Other language changes
704704
(Contributed by James Hilton-Balfe in :gh:`128335`.)
705705

706706
* The class :class:`memoryview` now supports the :c:expr:`float complex` and
707-
:c:expr:`double complex` C types: formatting characters ``'F'`` and ``'D'``
708-
respectively.
709-
(Contributed by Sergey B Kirpichev in :gh:`146151`.)
707+
:c:expr:`double complex` C types: formatting characters ``'F'``/``'Zf'``
708+
and ``'D'``/``'Zd'`` respectively.
709+
(Contributed by Victor Stinner in :gh:`146151` and :gh:`148675`.)
710710

711711
* Allow the *count* argument of :meth:`bytes.replace` to be a keyword.
712712
(Contributed by Stan Ulbrych in :gh:`147856`.)
@@ -757,13 +757,17 @@ array
757757
-----
758758

759759
* Support the :c:expr:`float complex` and :c:expr:`double complex` C types:
760-
formatting characters ``'F'`` and ``'D'`` respectively.
761-
(Contributed by Sergey B Kirpichev in :gh:`146151`.)
760+
formatting characters ``'F'``/``'Zf'`` and ``'D'``/``'Zd'`` respectively.
761+
(Contributed by Victor Stinner in :gh:`146151` and :gh:`148675`.)
762762

763763
* Support half-floats (16-bit IEEE 754 binary interchange format): formatting
764764
character ``'e'``.
765765
(Contributed by Sergey B Kirpichev in :gh:`146238`.)
766766

767+
* The :data:`array.typecodes` type changed from :class:`str` to :class:`tuple`
768+
to support type codes longer than 1 character (``Zf`` and ``Zd``).
769+
(Contributed by Victor Stinner in :gh:`148675`.)
770+
767771

768772
ast
769773
---
@@ -1774,6 +1778,12 @@ ctypes
17741778
which has been deprecated since Python 3.13.
17751779
(Contributed by Bénédikt Tran in :gh:`133866`.)
17761780

1781+
* Change the :py:attr:`~ctypes._SimpleCData._type_` of
1782+
:class:`~ctypes.c_float_complex`, :class:`~ctypes.c_double_complex` and
1783+
:class:`~ctypes.c_longdouble_complex` from ``F``, ``D`` and ``G`` to ``Zf``,
1784+
``Zd`` and ``Zg`` for compatibility with numpy.
1785+
(Contributed by Victor Stinner in :gh:`148675`.)
1786+
17771787

17781788
datetime
17791789
--------
@@ -2083,6 +2093,10 @@ New features
20832093

20842094
(Contributed by Victor Stinner in :gh:`141510`.)
20852095

2096+
* Add :c:func:`PyObject_CallFinalizerFromDealloc` function to the limited C
2097+
API.
2098+
(Contributed by Victor Stinner in :gh:`146063`.)
2099+
20862100
* Add :c:func:`PySys_GetAttr`, :c:func:`PySys_GetAttrString`,
20872101
:c:func:`PySys_GetOptionalAttr`, and :c:func:`PySys_GetOptionalAttrString`
20882102
functions as replacements for :c:func:`PySys_GetObject`.

Include/cpython/object.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ Py_DEPRECATED(3.15) PyAPI_FUNC(PyObject*) _PyObject_GetAttrId(PyObject *, _Py_Id
307307

308308
PyAPI_FUNC(PyObject **) _PyObject_GetDictPtr(PyObject *);
309309
PyAPI_FUNC(void) PyObject_CallFinalizer(PyObject *);
310-
PyAPI_FUNC(int) PyObject_CallFinalizerFromDealloc(PyObject *);
311310

312311
PyAPI_FUNC(void) PyUnstable_Object_ClearWeakRefsNoCallbacks(PyObject *);
313312

Include/object.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ PyAPI_FUNC(int) PyType_Freeze(PyTypeObject *type);
782782
#endif
783783

784784
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 15)
785+
PyAPI_FUNC(int) PyObject_CallFinalizerFromDealloc(PyObject *);
785786
PyAPI_FUNC(PyObject *) PyType_GetModuleByToken(PyTypeObject *type,
786787
const void *token);
787788
PyAPI_FUNC(void *) PyObject_GetTypeData_DuringGC(PyObject *obj,

Lib/ctypes/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,13 @@ class c_longdouble(_SimpleCData):
206206

207207
try:
208208
class c_double_complex(_SimpleCData):
209-
_type_ = "D"
209+
_type_ = "Zd"
210210
_check_size(c_double_complex)
211211
class c_float_complex(_SimpleCData):
212-
_type_ = "F"
212+
_type_ = "Zf"
213213
_check_size(c_float_complex)
214214
class c_longdouble_complex(_SimpleCData):
215-
_type_ = "G"
215+
_type_ = "Zg"
216216
except AttributeError:
217217
pass
218218

Lib/inspect.py

Lines changed: 99 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3351,6 +3351,95 @@ class BufferFlags(enum.IntFlag):
33513351
WRITE = 0x200
33523352

33533353

3354+
def _get_details_for_cli(module, nominal_target, resolved_target):
3355+
# Determine if the given module name is an alias for another module,
3356+
# or if it is reexporting a name that is actually defined elsewhere
3357+
resolved_module = getmodule(resolved_target)
3358+
if resolved_module is not None and resolved_module is not module:
3359+
# Referenced target indicates it was defined somewhere else,
3360+
# so report the details of that module rather than the lookup module
3361+
module = resolved_module
3362+
reported_module_name = module.__name__
3363+
# Ensure the reported source file reflects the actual defining location
3364+
try:
3365+
source_file = getsourcefile(resolved_target)
3366+
except Exception:
3367+
try:
3368+
source_file = getsourcefile(module)
3369+
except Exception:
3370+
source_file = None
3371+
# Determine if the nominal target location is its defining location
3372+
if resolved_target is module:
3373+
reported_target = reported_module_name
3374+
else:
3375+
reported_qualname = getattr(resolved_target, "__qualname__", None)
3376+
if not reported_qualname:
3377+
reported_qualname = nominal_target.partition(":")[2]
3378+
reported_target = f"{reported_module_name}:{reported_qualname}"
3379+
# Special case for looking up functions in frozen modules
3380+
if source_file == f"<frozen {reported_module_name}>":
3381+
source_file = module.__file__
3382+
# Populate the actual details to be reported
3383+
details = {
3384+
"target": reported_target,
3385+
"origin": module.__spec__.origin,
3386+
"cached": module.__spec__.cached,
3387+
"source": source_file,
3388+
}
3389+
if reported_target != nominal_target:
3390+
details["alias"] = nominal_target
3391+
error = None
3392+
if not source_file:
3393+
if module.__name__ in sys.builtin_module_names:
3394+
error = "No source code available for builtin module"
3395+
else:
3396+
error = "No source code available for defining module"
3397+
if resolved_target is module:
3398+
details["loader"] = repr(module.__spec__.loader)
3399+
if hasattr(module, '__path__'):
3400+
details["submodule_paths"] = str(module.__path__)
3401+
elif source_file:
3402+
try:
3403+
__, lineno = findsource(resolved_target)
3404+
except Exception:
3405+
error = "Failed to retrieve source code for given target"
3406+
else:
3407+
details["lineno"] = lineno
3408+
if error:
3409+
details["error"] = error
3410+
return details
3411+
3412+
def _render_details_for_cli(details):
3413+
resolved_target = details["target"]
3414+
alias = details.get("alias")
3415+
if alias:
3416+
rendered_target = f'{resolved_target} (looked up as "{alias}")'
3417+
else:
3418+
rendered_target = resolved_target
3419+
lines = [
3420+
f'Target: {rendered_target}',
3421+
f'Origin: {details["origin"]}',
3422+
f'Source: {details["source"]}',
3423+
f'Cached: {details["cached"]}',
3424+
]
3425+
loader = details.get("loader")
3426+
if loader:
3427+
lines.append(f'Loader: {loader}')
3428+
submodule_paths = details.get("submodule_paths")
3429+
if submodule_paths:
3430+
lines.append(f'Submodule search paths: {submodule_paths}')
3431+
else:
3432+
error = details.get("error")
3433+
if error:
3434+
# The error is only informational when retrieving object details
3435+
lines.append(error)
3436+
else:
3437+
lines.append(f'Line: {details["lineno"]}')
3438+
3439+
lines.append("")
3440+
return "\n".join(lines)
3441+
3442+
33543443
def _main():
33553444
""" Logic for inspecting an object given at command line """
33563445
import argparse
@@ -3367,6 +3456,8 @@ def _main():
33673456

33683457
args = parser.parse_args()
33693458

3459+
# We don't use `pkgutil.resolve_name` here because we want to obtain
3460+
# references to both the module *and* the fully resolved target object
33703461
target = args.object
33713462
mod_name, has_attrs, attrs = target.partition(":")
33723463
try:
@@ -3384,29 +3475,16 @@ def _main():
33843475
for part in parts:
33853476
obj = getattr(obj, part)
33863477

3387-
if module.__name__ in sys.builtin_module_names:
3388-
print("Can't get info for builtin modules.", file=sys.stderr)
3389-
sys.exit(1)
3390-
3478+
details = _get_details_for_cli(module, target, obj)
33913479
if args.details:
3392-
print(f'Target: {target}')
3393-
print(f'Origin: {getsourcefile(module)}')
3394-
print(f'Cached: {module.__spec__.cached}')
3395-
if obj is module:
3396-
print(f'Loader: {module.__loader__!r}')
3397-
if hasattr(module, '__path__'):
3398-
print(f'Submodule search path: {module.__path__}')
3399-
else:
3400-
try:
3401-
__, lineno = findsource(obj)
3402-
except Exception:
3403-
pass
3404-
else:
3405-
print(f'Line: {lineno}')
3406-
3407-
print()
3480+
print(_render_details_for_cli(details))
34083481
else:
3409-
print(getsource(obj))
3482+
# Attempt to render target source details
3483+
error = details.get("error")
3484+
if error:
3485+
sys.exit(error)
3486+
else:
3487+
print(getsource(obj))
34103488

34113489

34123490
if __name__ == "__main__":

0 commit comments

Comments
 (0)