Skip to content

Commit 6781a48

Browse files
authored
Merge branch 'main' into jspi-trampoline
2 parents 6358371 + baaac99 commit 6781a48

File tree

111 files changed

+3063
-1820
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+3063
-1820
lines changed

.gitattributes

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ PC/classicAppCompat.* binary
2424
[attr]noeol -text
2525

2626
Lib/test/cjkencodings/* noeol
27-
Lib/test/coding20731.py noeol
27+
Lib/test/tokenizedata/coding20731.py noeol
2828
Lib/test/decimaltestdata/*.decTest noeol
2929
Lib/test/test_email/data/*.txt noeol
3030
Lib/test/test_importlib/resources/data01/* noeol

.github/CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
# pre-commit
1111
.pre-commit-config.yaml @hugovk @AlexWaygood
12+
.ruff.toml @hugovk @AlexWaygood
1213

1314
# Build system
1415
configure* @erlend-aasland @corona10

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
# into the PR branch anyway.
6464
#
6565
# https://github.com/python/core-workflow/issues/373
66-
git diff --name-only origin/$GITHUB_BASE_REF.. | grep -qvE '(\.rst$|^Doc|^Misc)' && echo "run_tests=true" >> $GITHUB_OUTPUT || true
66+
git diff --name-only origin/$GITHUB_BASE_REF.. | grep -qvE '(\.rst$|^Doc|^Misc|^\.pre-commit-config\.yaml$|\.ruff\.toml$)' && echo "run_tests=true" >> $GITHUB_OUTPUT || true
6767
fi
6868
6969
# Check if we should run hypothesis tests

.github/workflows/lint.yml

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ on: [push, pull_request, workflow_dispatch]
55
permissions:
66
contents: read
77

8+
env:
9+
FORCE_COLOR: 1
10+
RUFF_FORMAT: github
11+
812
concurrency:
913
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
1014
cancel-in-progress: true

.github/workflows/require-pr-label.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ on:
55
types: [opened, reopened, labeled, unlabeled, synchronize]
66

77
permissions:
8-
issues: read
9-
pull-requests: read
8+
issues: write
9+
pull-requests: write
1010

1111
jobs:
1212
label:

.pre-commit-config.yaml

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.0.288
4+
hooks:
5+
- id: ruff
6+
name: Run Ruff on Lib/test/
7+
args: [--exit-non-zero-on-fix]
8+
files: ^Lib/test/
9+
210
- repo: https://github.com/pre-commit/pre-commit-hooks
311
rev: v4.4.0
412
hooks:
13+
- id: check-toml
14+
exclude: ^Lib/test/test_tomllib/
515
- id: check-yaml
616
- id: end-of-file-fixer
717
types: [python]
8-
exclude: Lib/test/coding20731.py
18+
exclude: Lib/test/tokenizedata/coding20731.py
919
- id: trailing-whitespace
1020
types_or: [c, python, rst]
1121

Doc/library/dis.rst

+38-28
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ not have to be) the original ``STACK[-2]``.
597597

598598
key = STACK.pop()
599599
container = STACK.pop()
600-
STACK.append(container[index])
600+
STACK.append(container[key])
601601

602602

603603
.. opcode:: STORE_SUBSCR
@@ -1122,7 +1122,8 @@ iterations of the loop.
11221122
This bytecode distinguishes two cases: if ``STACK[-1]`` has a method with the
11231123
correct name, the bytecode pushes the unbound method and ``STACK[-1]``.
11241124
``STACK[-1]`` will be used as the first argument (``self``) by :opcode:`CALL`
1125-
when calling the unbound method. Otherwise, ``NULL`` and the object returned by
1125+
or :opcode:`CALL_KW` when calling the unbound method.
1126+
Otherwise, ``NULL`` and the object returned by
11261127
the attribute lookup are pushed.
11271128

11281129
.. versionchanged:: 3.12
@@ -1390,32 +1391,48 @@ iterations of the loop.
13901391

13911392
.. opcode:: CALL (argc)
13921393

1393-
Calls a callable object with the number of arguments specified by ``argc``,
1394-
including the named arguments specified by the preceding
1395-
:opcode:`KW_NAMES`, if any.
1396-
On the stack are (in ascending order), either:
1394+
Calls a callable object with the number of arguments specified by ``argc``.
1395+
On the stack are (in ascending order):
13971396

1398-
* NULL
13991397
* The callable
1400-
* The positional arguments
1401-
* The named arguments
1402-
1403-
or:
1404-
1405-
* The callable
1406-
* ``self``
1398+
* ``self`` or ``NULL``
14071399
* The remaining positional arguments
1408-
* The named arguments
14091400

1410-
``argc`` is the total of the positional and named arguments, excluding
1411-
``self`` when a ``NULL`` is not present.
1401+
``argc`` is the total of the positional arguments, excluding ``self``.
14121402

14131403
``CALL`` pops all arguments and the callable object off the stack,
14141404
calls the callable object with those arguments, and pushes the return value
14151405
returned by the callable object.
14161406

14171407
.. versionadded:: 3.11
14181408

1409+
.. versionchanged:: 3.13
1410+
The callable now always appears at the same position on the stack.
1411+
1412+
.. versionchanged:: 3.13
1413+
Calls with keyword arguments are now handled by :opcode:`CALL_KW`.
1414+
1415+
1416+
.. opcode:: CALL_KW (argc)
1417+
1418+
Calls a callable object with the number of arguments specified by ``argc``,
1419+
including one or more named arguments. On the stack are (in ascending order):
1420+
1421+
* The callable
1422+
* ``self`` or ``NULL``
1423+
* The remaining positional arguments
1424+
* The named arguments
1425+
* A :class:`tuple` of keyword argument names
1426+
1427+
``argc`` is the total of the positional and named arguments, excluding ``self``.
1428+
The length of the tuple of keyword argument names is the number of named arguments.
1429+
1430+
``CALL_KW`` pops all arguments, the keyword names, and the callable object
1431+
off the stack, calls the callable object with those arguments, and pushes the
1432+
return value returned by the callable object.
1433+
1434+
.. versionadded:: 3.13
1435+
14191436

14201437
.. opcode:: CALL_FUNCTION_EX (flags)
14211438

@@ -1441,15 +1458,6 @@ iterations of the loop.
14411458
.. versionadded:: 3.11
14421459

14431460

1444-
.. opcode:: KW_NAMES (consti)
1445-
1446-
Prefixes :opcode:`CALL`.
1447-
Stores a reference to ``co_consts[consti]`` into an internal variable
1448-
for use by :opcode:`CALL`. ``co_consts[consti]`` must be a tuple of strings.
1449-
1450-
.. versionadded:: 3.11
1451-
1452-
14531461
.. opcode:: MAKE_FUNCTION
14541462

14551463
Pushes a new function object on the stack built from the code object at ``STACK[1]``.
@@ -1611,8 +1619,8 @@ iterations of the loop.
16111619
opcodes in the range [0,255] which don't use their argument and those
16121620
that do (``< HAVE_ARGUMENT`` and ``>= HAVE_ARGUMENT``, respectively).
16131621

1614-
If your application uses pseudo instructions, use the :data:`hasarg`
1615-
collection instead.
1622+
If your application uses pseudo instructions or specialized instructions,
1623+
use the :data:`hasarg` collection instead.
16161624

16171625
.. versionchanged:: 3.6
16181626
Now every instruction has an argument, but opcodes ``< HAVE_ARGUMENT``
@@ -1623,6 +1631,8 @@ iterations of the loop.
16231631
it is not true that comparison with ``HAVE_ARGUMENT`` indicates whether
16241632
they use their arg.
16251633

1634+
.. deprecated:: 3.13
1635+
Use :data:`hasarg` instead.
16261636

16271637
.. opcode:: CALL_INTRINSIC_1
16281638

Doc/library/importlib.resources.abc.rst

-12
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
:const:`None`. An object compatible with this ABC should only be
4444
returned when the specified module is a package.
4545

46-
.. versionadded:: 3.7
47-
4846
.. deprecated-removed:: 3.12 3.14
4947
Use :class:`importlib.resources.abc.TraversableResources` instead.
5048

@@ -95,11 +93,6 @@
9593
For a representation of the object on the file-system, use
9694
:meth:`importlib.resources.as_file`.
9795

98-
.. versionadded:: 3.9
99-
100-
.. deprecated-removed:: 3.12 3.14
101-
Use :class:`importlib.resources.abc.Traversable` instead.
102-
10396
.. attribute:: name
10497

10598
Abstract. The base name of this object without any parent references.
@@ -153,11 +146,6 @@
153146
Loaders that wish to support resource reading are expected to
154147
implement this interface.
155148

156-
.. versionadded:: 3.9
157-
158-
.. deprecated-removed:: 3.12 3.14
159-
Use :class:`importlib.resources.abc.TraversableResources` instead.
160-
161149
.. abstractmethod:: files()
162150

163151
Returns a :class:`importlib.resources.abc.Traversable` object for the loaded

Doc/library/importlib.rst

+154
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,160 @@ ABC hierarchy::
645645
itself does not end in ``__init__``.
646646

647647

648+
.. class:: ResourceReader
649+
650+
*Superseded by TraversableResources*
651+
652+
An :term:`abstract base class` to provide the ability to read
653+
*resources*.
654+
655+
From the perspective of this ABC, a *resource* is a binary
656+
artifact that is shipped within a package. Typically this is
657+
something like a data file that lives next to the ``__init__.py``
658+
file of the package. The purpose of this class is to help abstract
659+
out the accessing of such data files so that it does not matter if
660+
the package and its data file(s) are stored in a e.g. zip file
661+
versus on the file system.
662+
663+
For any of methods of this class, a *resource* argument is
664+
expected to be a :term:`path-like object` which represents
665+
conceptually just a file name. This means that no subdirectory
666+
paths should be included in the *resource* argument. This is
667+
because the location of the package the reader is for, acts as the
668+
"directory". Hence the metaphor for directories and file
669+
names is packages and resources, respectively. This is also why
670+
instances of this class are expected to directly correlate to
671+
a specific package (instead of potentially representing multiple
672+
packages or a module).
673+
674+
Loaders that wish to support resource reading are expected to
675+
provide a method called ``get_resource_reader(fullname)`` which
676+
returns an object implementing this ABC's interface. If the module
677+
specified by fullname is not a package, this method should return
678+
:const:`None`. An object compatible with this ABC should only be
679+
returned when the specified module is a package.
680+
681+
.. versionadded:: 3.7
682+
683+
.. deprecated-removed:: 3.12 3.14
684+
Use :class:`importlib.resources.abc.TraversableResources` instead.
685+
686+
.. abstractmethod:: open_resource(resource)
687+
688+
Returns an opened, :term:`file-like object` for binary reading
689+
of the *resource*.
690+
691+
If the resource cannot be found, :exc:`FileNotFoundError` is
692+
raised.
693+
694+
.. abstractmethod:: resource_path(resource)
695+
696+
Returns the file system path to the *resource*.
697+
698+
If the resource does not concretely exist on the file system,
699+
raise :exc:`FileNotFoundError`.
700+
701+
.. abstractmethod:: is_resource(name)
702+
703+
Returns ``True`` if the named *name* is considered a resource.
704+
:exc:`FileNotFoundError` is raised if *name* does not exist.
705+
706+
.. abstractmethod:: contents()
707+
708+
Returns an :term:`iterable` of strings over the contents of
709+
the package. Do note that it is not required that all names
710+
returned by the iterator be actual resources, e.g. it is
711+
acceptable to return names for which :meth:`is_resource` would
712+
be false.
713+
714+
Allowing non-resource names to be returned is to allow for
715+
situations where how a package and its resources are stored
716+
are known a priori and the non-resource names would be useful.
717+
For instance, returning subdirectory names is allowed so that
718+
when it is known that the package and resources are stored on
719+
the file system then those subdirectory names can be used
720+
directly.
721+
722+
The abstract method returns an iterable of no items.
723+
724+
725+
.. class:: Traversable
726+
727+
An object with a subset of :class:`pathlib.Path` methods suitable for
728+
traversing directories and opening files.
729+
730+
For a representation of the object on the file-system, use
731+
:meth:`importlib.resources.as_file`.
732+
733+
.. versionadded:: 3.9
734+
735+
.. deprecated-removed:: 3.12 3.14
736+
Use :class:`importlib.resources.abc.Traversable` instead.
737+
738+
.. attribute:: name
739+
740+
Abstract. The base name of this object without any parent references.
741+
742+
.. abstractmethod:: iterdir()
743+
744+
Yield ``Traversable`` objects in ``self``.
745+
746+
.. abstractmethod:: is_dir()
747+
748+
Return ``True`` if ``self`` is a directory.
749+
750+
.. abstractmethod:: is_file()
751+
752+
Return ``True`` if ``self`` is a file.
753+
754+
.. abstractmethod:: joinpath(child)
755+
756+
Return Traversable child in ``self``.
757+
758+
.. abstractmethod:: __truediv__(child)
759+
760+
Return ``Traversable`` child in ``self``.
761+
762+
.. abstractmethod:: open(mode='r', *args, **kwargs)
763+
764+
*mode* may be 'r' or 'rb' to open as text or binary. Return a handle
765+
suitable for reading (same as :attr:`pathlib.Path.open`).
766+
767+
When opening as text, accepts encoding parameters such as those
768+
accepted by :attr:`io.TextIOWrapper`.
769+
770+
.. method:: read_bytes()
771+
772+
Read contents of ``self`` as bytes.
773+
774+
.. method:: read_text(encoding=None)
775+
776+
Read contents of ``self`` as text.
777+
778+
779+
.. class:: TraversableResources
780+
781+
An abstract base class for resource readers capable of serving
782+
the :meth:`importlib.resources.files` interface. Subclasses
783+
:class:`importlib.resources.abc.ResourceReader` and provides
784+
concrete implementations of the :class:`importlib.resources.abc.ResourceReader`'s
785+
abstract methods. Therefore, any loader supplying
786+
:class:`importlib.abc.TraversableResources` also supplies ResourceReader.
787+
788+
Loaders that wish to support resource reading are expected to
789+
implement this interface.
790+
791+
.. versionadded:: 3.9
792+
793+
.. deprecated-removed:: 3.12 3.14
794+
Use :class:`importlib.resources.abc.TraversableResources` instead.
795+
796+
.. abstractmethod:: files()
797+
798+
Returns a :class:`importlib.resources.abc.Traversable` object for the loaded
799+
package.
800+
801+
648802

649803
:mod:`importlib.machinery` -- Importers and path hooks
650804
------------------------------------------------------

0 commit comments

Comments
 (0)