Skip to content

Commit cf578bd

Browse files
author
NGRsoftlab
authored
Merge branch 'main' into fix-issue-116180
2 parents 85d9f47 + 2a54c4b commit cf578bd

Some content is hidden

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

59 files changed

+971
-594
lines changed

.devcontainer/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ FROM docker.io/library/fedora:37
22

33
ENV CC=clang
44

5-
ENV WASI_SDK_VERSION=20
5+
ENV WASI_SDK_VERSION=21
66
ENV WASI_SDK_PATH=/opt/wasi-sdk
77

88
ENV WASMTIME_HOME=/opt/wasmtime
9-
ENV WASMTIME_VERSION=18.0.2
9+
ENV WASMTIME_VERSION=18.0.3
1010
ENV WASMTIME_CPU_ARCH=x86_64
1111

1212
RUN dnf -y --nodocs --setopt=install_weak_deps=False install /usr/bin/{blurb,clang,curl,git,ln,tar,xz} 'dnf-command(builddep)' && \

.github/workflows/reusable-wasi.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ jobs:
1111
timeout-minutes: 60
1212
runs-on: ubuntu-20.04
1313
env:
14-
WASMTIME_VERSION: 18.0.2
15-
WASI_SDK_VERSION: 20
14+
WASMTIME_VERSION: 18.0.3
15+
WASI_SDK_VERSION: 21
1616
WASI_SDK_PATH: /opt/wasi-sdk
1717
CROSS_BUILD_PYTHON: cross-build/build
1818
CROSS_BUILD_WASI: cross-build/wasm32-wasi

Doc/c-api/long.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
450450
a “fast path” for small integers. For compact values use
451451
:c:func:`PyUnstable_Long_CompactValue`; for others fall back to a
452452
:c:func:`PyLong_As* <PyLong_AsSize_t>` function or
453-
:c:func:`calling <PyObject_CallMethod>` :meth:`int.to_bytes`.
453+
:c:func:`PyLong_AsNativeBytes`.
454454
455455
The speedup is expected to be negligible for most users.
456456

Doc/howto/logging-cookbook.rst

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3418,9 +3418,10 @@ The worker thread is implemented using Qt's ``QThread`` class rather than the
34183418
:mod:`threading` module, as there are circumstances where one has to use
34193419
``QThread``, which offers better integration with other ``Qt`` components.
34203420

3421-
The code should work with recent releases of either ``PySide2`` or ``PyQt5``.
3422-
You should be able to adapt the approach to earlier versions of Qt. Please
3423-
refer to the comments in the code snippet for more detailed information.
3421+
The code should work with recent releases of either ``PySide6``, ``PyQt6``,
3422+
``PySide2`` or ``PyQt5``. You should be able to adapt the approach to earlier
3423+
versions of Qt. Please refer to the comments in the code snippet for more
3424+
detailed information.
34243425

34253426
.. code-block:: python3
34263427
@@ -3430,16 +3431,25 @@ refer to the comments in the code snippet for more detailed information.
34303431
import sys
34313432
import time
34323433
3433-
# Deal with minor differences between PySide2 and PyQt5
3434+
# Deal with minor differences between different Qt packages
34343435
try:
3435-
from PySide2 import QtCore, QtGui, QtWidgets
3436+
from PySide6 import QtCore, QtGui, QtWidgets
34363437
Signal = QtCore.Signal
34373438
Slot = QtCore.Slot
34383439
except ImportError:
3439-
from PyQt5 import QtCore, QtGui, QtWidgets
3440-
Signal = QtCore.pyqtSignal
3441-
Slot = QtCore.pyqtSlot
3442-
3440+
try:
3441+
from PyQt6 import QtCore, QtGui, QtWidgets
3442+
Signal = QtCore.pyqtSignal
3443+
Slot = QtCore.pyqtSlot
3444+
except ImportError:
3445+
try:
3446+
from PySide2 import QtCore, QtGui, QtWidgets
3447+
Signal = QtCore.Signal
3448+
Slot = QtCore.Slot
3449+
except ImportError:
3450+
from PyQt5 import QtCore, QtGui, QtWidgets
3451+
Signal = QtCore.pyqtSignal
3452+
Slot = QtCore.pyqtSlot
34433453
34443454
logger = logging.getLogger(__name__)
34453455
@@ -3511,8 +3521,14 @@ refer to the comments in the code snippet for more detailed information.
35113521
while not QtCore.QThread.currentThread().isInterruptionRequested():
35123522
delay = 0.5 + random.random() * 2
35133523
time.sleep(delay)
3514-
level = random.choice(LEVELS)
3515-
logger.log(level, 'Message after delay of %3.1f: %d', delay, i, extra=extra)
3524+
try:
3525+
if random.random() < 0.1:
3526+
raise ValueError('Exception raised: %d' % i)
3527+
else:
3528+
level = random.choice(LEVELS)
3529+
logger.log(level, 'Message after delay of %3.1f: %d', delay, i, extra=extra)
3530+
except ValueError as e:
3531+
logger.exception('Failed: %s', e, extra=extra)
35163532
i += 1
35173533
35183534
#
@@ -3539,7 +3555,10 @@ refer to the comments in the code snippet for more detailed information.
35393555
self.textedit = te = QtWidgets.QPlainTextEdit(self)
35403556
# Set whatever the default monospace font is for the platform
35413557
f = QtGui.QFont('nosuchfont')
3542-
f.setStyleHint(f.Monospace)
3558+
if hasattr(f, 'Monospace'):
3559+
f.setStyleHint(f.Monospace)
3560+
else:
3561+
f.setStyleHint(f.StyleHint.Monospace) # for Qt6
35433562
te.setFont(f)
35443563
te.setReadOnly(True)
35453564
PB = QtWidgets.QPushButton
@@ -3626,7 +3645,11 @@ refer to the comments in the code snippet for more detailed information.
36263645
app = QtWidgets.QApplication(sys.argv)
36273646
example = Window(app)
36283647
example.show()
3629-
sys.exit(app.exec_())
3648+
if hasattr(app, 'exec'):
3649+
rc = app.exec()
3650+
else:
3651+
rc = app.exec_()
3652+
sys.exit(rc)
36303653
36313654
if __name__=='__main__':
36323655
main()

Doc/howto/logging.rst

Lines changed: 41 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ or *severity*.
2525
When to use logging
2626
^^^^^^^^^^^^^^^^^^^
2727

28-
Logging provides a set of convenience functions for simple logging usage. These
29-
are :func:`debug`, :func:`info`, :func:`warning`, :func:`error` and
30-
:func:`critical`. To determine when to use logging, see the table below, which
31-
states, for each of a set of common tasks, the best tool to use for it.
28+
You can access logging functionality by creating a logger via ``logger =
29+
getLogger(__name__)``, and then calling the logger's :meth:`~Logger.debug`,
30+
:meth:`~Logger.info`, :meth:`~Logger.warning`, :meth:`~Logger.error` and
31+
:meth:`~Logger.critical` methods. To determine when to use logging, and to see
32+
which logger methods to use when, see the table below. It states, for each of a
33+
set of common tasks, the best tool to use for that task.
3234

3335
+-------------------------------------+--------------------------------------+
3436
| Task you want to perform | The best tool for the task |
@@ -37,8 +39,8 @@ states, for each of a set of common tasks, the best tool to use for it.
3739
| usage of a command line script or | |
3840
| program | |
3941
+-------------------------------------+--------------------------------------+
40-
| Report events that occur during | :func:`logging.info` (or |
41-
| normal operation of a program (e.g. | :func:`logging.debug` for very |
42+
| Report events that occur during | A logger's :meth:`~Logger.info` (or |
43+
| normal operation of a program (e.g. | :meth:`~Logger.debug` method for very|
4244
| for status monitoring or fault | detailed output for diagnostic |
4345
| investigation) | purposes) |
4446
+-------------------------------------+--------------------------------------+
@@ -47,22 +49,23 @@ states, for each of a set of common tasks, the best tool to use for it.
4749
| | the client application should be |
4850
| | modified to eliminate the warning |
4951
| | |
50-
| | :func:`logging.warning` if there is |
51-
| | nothing the client application can do|
52-
| | about the situation, but the event |
53-
| | should still be noted |
52+
| | A logger's :meth:`~Logger.warning` |
53+
| | method if there is nothing the client|
54+
| | application can do about the |
55+
| | situation, but the event should still|
56+
| | be noted |
5457
+-------------------------------------+--------------------------------------+
5558
| Report an error regarding a | Raise an exception |
5659
| particular runtime event | |
5760
+-------------------------------------+--------------------------------------+
58-
| Report suppression of an error | :func:`logging.error`, |
59-
| without raising an exception (e.g. | :func:`logging.exception` or |
60-
| error handler in a long-running | :func:`logging.critical` as |
61+
| Report suppression of an error | A logger's :meth:`~Logger.error`, |
62+
| without raising an exception (e.g. | :meth:`~Logger.exception` or |
63+
| error handler in a long-running | :meth:`~Logger.critical` method as |
6164
| server process) | appropriate for the specific error |
6265
| | and application domain |
6366
+-------------------------------------+--------------------------------------+
6467

65-
The logging functions are named after the level or severity of the events
68+
The logger methods are named after the level or severity of the events
6669
they are used to track. The standard levels and their applicability are
6770
described below (in increasing order of severity):
6871

@@ -115,12 +118,18 @@ If you type these lines into a script and run it, you'll see:
115118
WARNING:root:Watch out!
116119
117120
printed out on the console. The ``INFO`` message doesn't appear because the
118-
default level is ``WARNING``. The printed message includes the indication of
119-
the level and the description of the event provided in the logging call, i.e.
120-
'Watch out!'. Don't worry about the 'root' part for now: it will be explained
121-
later. The actual output can be formatted quite flexibly if you need that;
122-
formatting options will also be explained later.
123-
121+
default level is ``WARNING``. The printed message includes the indication of the
122+
level and the description of the event provided in the logging call, i.e.
123+
'Watch out!'. The actual output can be formatted quite flexibly if you need
124+
that; formatting options will also be explained later.
125+
126+
Notice that in this example, we use functions directly on the ``logging``
127+
module, like ``logging.debug``, rather than creating a logger and calling
128+
functions on it. These functions operation on the root logger, but can be useful
129+
as they will call :func:`~logging.basicConfig` for you if it has not been called yet, like in
130+
this example. In larger programs you'll usually want to control the logging
131+
configuration explicitly however - so for that reason as well as others, it's
132+
better to create loggers and call their methods.
124133

125134
Logging to a file
126135
^^^^^^^^^^^^^^^^^
@@ -130,11 +139,12 @@ look at that next. Be sure to try the following in a newly started Python
130139
interpreter, and don't just continue from the session described above::
131140

132141
import logging
142+
logger = logging.getLogger(__name__)
133143
logging.basicConfig(filename='example.log', encoding='utf-8', level=logging.DEBUG)
134-
logging.debug('This message should go to the log file')
135-
logging.info('So should this')
136-
logging.warning('And this, too')
137-
logging.error('And non-ASCII stuff, too, like Øresund and Malmö')
144+
logger.debug('This message should go to the log file')
145+
logger.info('So should this')
146+
logger.warning('And this, too')
147+
logger.error('And non-ASCII stuff, too, like Øresund and Malmö')
138148

139149
.. versionchanged:: 3.9
140150
The *encoding* argument was added. In earlier Python versions, or if not
@@ -148,10 +158,10 @@ messages:
148158

149159
.. code-block:: none
150160
151-
DEBUG:root:This message should go to the log file
152-
INFO:root:So should this
153-
WARNING:root:And this, too
154-
ERROR:root:And non-ASCII stuff, too, like Øresund and Malmö
161+
DEBUG:__main__:This message should go to the log file
162+
INFO:__main__:So should this
163+
WARNING:__main__:And this, too
164+
ERROR:__main__:And non-ASCII stuff, too, like Øresund and Malmö
155165
156166
This example also shows how you can set the logging level which acts as the
157167
threshold for tracking. In this case, because we set the threshold to
@@ -180,11 +190,9 @@ following example::
180190
raise ValueError('Invalid log level: %s' % loglevel)
181191
logging.basicConfig(level=numeric_level, ...)
182192

183-
The call to :func:`basicConfig` should come *before* any calls to
184-
:func:`debug`, :func:`info`, etc. Otherwise, those functions will call
185-
:func:`basicConfig` for you with the default options. As it's intended as a
186-
one-off simple configuration facility, only the first call will actually do
187-
anything: subsequent calls are effectively no-ops.
193+
The call to :func:`basicConfig` should come *before* any calls to a logger's
194+
methods such as :meth:`~Logger.debug`, :meth:`~Logger.info`, etc. Otherwise,
195+
that logging event may not be handled in the desired manner.
188196

189197
If you run the above script several times, the messages from successive runs
190198
are appended to the file *example.log*. If you want each run to start afresh,
@@ -197,50 +205,6 @@ The output will be the same as before, but the log file is no longer appended
197205
to, so the messages from earlier runs are lost.
198206

199207

200-
Logging from multiple modules
201-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
202-
203-
If your program consists of multiple modules, here's an example of how you
204-
could organize logging in it::
205-
206-
# myapp.py
207-
import logging
208-
import mylib
209-
210-
def main():
211-
logging.basicConfig(filename='myapp.log', level=logging.INFO)
212-
logging.info('Started')
213-
mylib.do_something()
214-
logging.info('Finished')
215-
216-
if __name__ == '__main__':
217-
main()
218-
219-
::
220-
221-
# mylib.py
222-
import logging
223-
224-
def do_something():
225-
logging.info('Doing something')
226-
227-
If you run *myapp.py*, you should see this in *myapp.log*:
228-
229-
.. code-block:: none
230-
231-
INFO:root:Started
232-
INFO:root:Doing something
233-
INFO:root:Finished
234-
235-
which is hopefully what you were expecting to see. You can generalize this to
236-
multiple modules, using the pattern in *mylib.py*. Note that for this simple
237-
usage pattern, you won't know, by looking in the log file, *where* in your
238-
application your messages came from, apart from looking at the event
239-
description. If you want to track the location of your messages, you'll need
240-
to refer to the documentation beyond the tutorial level -- see
241-
:ref:`logging-advanced-tutorial`.
242-
243-
244208
Logging variable data
245209
^^^^^^^^^^^^^^^^^^^^^
246210

0 commit comments

Comments
 (0)