Skip to content

Commit f86569c

Browse files
Merge branch 'main' into instrumentation
2 parents 443fc76 + d8fa40b commit f86569c

Some content is hidden

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

41 files changed

+1402
-494
lines changed

Doc/extending/extending.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ and initialize it by calling :c:func:`PyErr_NewException` in the module's
214214

215215
SpamError = PyErr_NewException("spam.error", NULL, NULL);
216216

217-
Since :c:data:`!SpamError` is a global variable, it will be overwitten every time
217+
Since :c:data:`!SpamError` is a global variable, it will be overwritten every time
218218
the module is reinitialized, when the :c:data:`Py_mod_exec` function is called.
219219

220220
For now, let's avoid the issue: we will block repeated initialization by raising an

Doc/howto/free-threading-extensions.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ that return :term:`strong references <strong reference>`.
161161
+===================================+===================================+
162162
| :c:func:`PyList_GetItem` | :c:func:`PyList_GetItemRef` |
163163
+-----------------------------------+-----------------------------------+
164+
| :c:func:`PyList_GET_ITEM` | :c:func:`PyList_GetItemRef` |
165+
+-----------------------------------+-----------------------------------+
164166
| :c:func:`PyDict_GetItem` | :c:func:`PyDict_GetItemRef` |
165167
+-----------------------------------+-----------------------------------+
166168
| :c:func:`PyDict_GetItemWithError` | :c:func:`PyDict_GetItemRef` |

Doc/library/bdb.rst

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,8 @@ The :mod:`bdb` module also defines two classes:
192192
entered.
193193
* ``"return"``: A function or other code block is about to return.
194194
* ``"exception"``: An exception has occurred.
195-
* ``"c_call"``: A C function is about to be called.
196-
* ``"c_return"``: A C function has returned.
197-
* ``"c_exception"``: A C function has raised an exception.
198195

199-
For the Python events, specialized functions (see below) are called. For
200-
the C events, no action is taken.
196+
For all the events, specialized functions (see below) are called.
201197

202198
The *arg* parameter depends on the previous event.
203199

Doc/library/importlib.resources.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ within *packages*.
1616
"Resources" are file-like resources associated with a module or package in
1717
Python. The resources may be contained directly in a package, within a
1818
subdirectory contained in that package, or adjacent to modules outside a
19-
package. Resources may be text or binary. As a result, Python module sources
20-
(.py) of a package and compilation artifacts (pycache) are technically
21-
de-facto resources of that package. In practice, however, resources are
22-
primarily those non-Python artifacts exposed specifically by the package
23-
author.
19+
package. Resources may be text or binary. As a result, a package's Python
20+
module sources (.py), compilation artifacts (pycache), and installation
21+
artifacts (like :func:`reserved filenames <os.path.isreserved>`
22+
in directories) are technically de-facto resources of that package.
23+
In practice, however, resources are primarily those non-Python artifacts
24+
exposed specifically by the package author.
2425

2526
Resources can be opened or read in either binary or text mode.
2627

Doc/library/shelve.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Restrictions
144144
which can cause hard crashes when trying to read from the database.
145145

146146
* :meth:`Shelf.reorganize` may not be available for all database packages and
147-
may temporarely increase resource usage (especially disk space) when called.
147+
may temporarily increase resource usage (especially disk space) when called.
148148
Additionally, it will never run automatically and instead needs to be called
149149
explicitly.
150150

Doc/reference/expressions.rst

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,18 @@ Literals
133133

134134
Python supports string and bytes literals and various numeric literals:
135135

136-
.. productionlist:: python-grammar
137-
literal: `stringliteral` | `bytesliteral` | `NUMBER`
136+
.. grammar-snippet::
137+
:group: python-grammar
138+
139+
literal: `strings` | `NUMBER`
138140

139141
Evaluation of a literal yields an object of the given type (string, bytes,
140142
integer, floating-point number, complex number) with the given value. The value
141143
may be approximated in the case of floating-point and imaginary (complex)
142-
literals. See section :ref:`literals` for details.
144+
literals.
145+
See section :ref:`literals` for details.
146+
See section :ref:`string-concatenation` for details on ``strings``.
147+
143148

144149
.. index::
145150
triple: immutable; data; type
@@ -152,6 +157,58 @@ occurrence) may obtain the same object or a different object with the same
152157
value.
153158

154159

160+
.. _string-concatenation:
161+
162+
String literal concatenation
163+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
164+
165+
Multiple adjacent string or bytes literals (delimited by whitespace), possibly
166+
using different quoting conventions, are allowed, and their meaning is the same
167+
as their concatenation::
168+
169+
>>> "hello" 'world'
170+
"helloworld"
171+
172+
Formally:
173+
174+
.. grammar-snippet::
175+
:group: python-grammar
176+
177+
strings: ( `STRING` | fstring)+ | tstring+
178+
179+
This feature is defined at the syntactical level, so it only works with literals.
180+
To concatenate string expressions at run time, the '+' operator may be used::
181+
182+
>>> greeting = "Hello"
183+
>>> space = " "
184+
>>> name = "Blaise"
185+
>>> print(greeting + space + name) # not: print(greeting space name)
186+
Hello Blaise
187+
188+
Literal concatenation can freely mix raw strings, triple-quoted strings,
189+
and formatted string literals.
190+
For example::
191+
192+
>>> "Hello" r', ' f"{name}!"
193+
"Hello, Blaise!"
194+
195+
This feature can be used to reduce the number of backslashes
196+
needed, to split long strings conveniently across long lines, or even to add
197+
comments to parts of strings. For example::
198+
199+
re.compile("[A-Za-z_]" # letter or underscore
200+
"[A-Za-z0-9_]*" # letter, digit or underscore
201+
)
202+
203+
However, bytes literals may only be combined with other byte literals;
204+
not with string literals of any kind.
205+
Also, template string literals may only be combined with other template
206+
string literals::
207+
208+
>>> t"Hello" t"{name}!"
209+
Template(strings=('Hello', '!'), interpolations=(...))
210+
211+
155212
.. _parenthesized:
156213

157214
Parenthesized forms

Doc/reference/grammar.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ error recovery.
1010

1111
The notation used here is the same as in the preceding docs,
1212
and is described in the :ref:`notation <notation>` section,
13-
except for a few extra complications:
13+
except for an extra complication:
1414

15-
* ``&e``: a positive lookahead (that is, ``e`` is required to match but
16-
not consumed)
17-
* ``!e``: a negative lookahead (that is, ``e`` is required *not* to match)
1815
* ``~`` ("cut"): commit to the current alternative and fail the rule
1916
even if this fails to parse
2017

Doc/reference/introduction.rst

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,23 @@ The definition to the right of the colon uses the following syntax elements:
145145
* ``e?``: A question mark has exactly the same meaning as square brackets:
146146
the preceding item is optional.
147147
* ``(e)``: Parentheses are used for grouping.
148+
149+
The following notation is only used in
150+
:ref:`lexical definitions <notation-lexical-vs-syntactic>`.
151+
148152
* ``"a"..."z"``: Two literal characters separated by three dots mean a choice
149153
of any single character in the given (inclusive) range of ASCII characters.
150-
This notation is only used in
151-
:ref:`lexical definitions <notation-lexical-vs-syntactic>`.
152154
* ``<...>``: A phrase between angular brackets gives an informal description
153155
of the matched symbol (for example, ``<any ASCII character except "\">``),
154156
or an abbreviation that is defined in nearby text (for example, ``<Lu>``).
155-
This notation is only used in
156-
:ref:`lexical definitions <notation-lexical-vs-syntactic>`.
157+
158+
.. _lexical-lookaheads:
159+
160+
Some definitions also use *lookaheads*, which indicate that an element
161+
must (or must not) match at a given position, but without consuming any input:
162+
163+
* ``&e``: a positive lookahead (that is, ``e`` is required to match)
164+
* ``!e``: a negative lookahead (that is, ``e`` is required *not* to match)
157165

158166
The unary operators (``*``, ``+``, ``?``) bind as tightly as possible;
159167
the vertical bar (``|``) binds most loosely.

0 commit comments

Comments
 (0)