Skip to content

Commit 8bba5da

Browse files
committed
Merge branch 'main' into typewatch
* main: (40 commits) pythongh-98461: Fix source location in comprehensions bytecode (pythonGH-98464) pythongh-98421: Clean Up PyObject_Print (pythonGH-98422) pythongh-98360: multiprocessing now spawns children on Windows with correct argv[0] in virtual environments (pythonGH-98462) CODEOWNERS: Become a typing code owner (python#98480) [doc] Improve logging cookbook example. (pythonGH-98481) Add more tkinter.Canvas tests (pythonGH-98475) pythongh-95023: Added os.setns and os.unshare functions (python#95046) pythonGH-98363: Presize the list for batched() (pythonGH-98419) pythongh-98374: Suppress ImportError for invalid query for help() command. (pythongh-98450) typing tests: `_overload_dummy` raises `NotImplementedError`, not `RuntimeError` (python#98351) pythongh-98354: Add unicode check for 'name' attribute in _imp_create_builtin (pythonGH-98412) pythongh-98257: Make _PyEval_SetTrace() reentrant (python#98258) pythongh-98414: py.exe launcher does not use defaults for -V:company/ option (pythonGH-98460) pythongh-98417: Store int_max_str_digits on the Interpreter State (pythonGH-98418) Doc: Remove title text from internal links (python#98409) [doc] Refresh the venv introduction documentation, and correct the statement about VIRTUAL_ENV (pythonGH-98350) Docs: Bump sphinx-lint and fix unbalanced inline literal markup (python#98441) pythongh-92886: Replace assertion statements in `handlers.BaseHandler` to support running with optimizations (`-O`) (pythonGH-93231) pythongh-92886: Fix tests that fail when running with optimizations (`-O`) in `_test_multiprocessing.py` (pythonGH-93233) pythongh-92886: Fix tests that fail when running with optimizations (`-O`) in `test_py_compile.py` (pythonGH-93235) ...
2 parents 4329743 + 4ec9ed8 commit 8bba5da

File tree

79 files changed

+2082
-600
lines changed

Some content is hidden

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

79 files changed

+2082
-600
lines changed

.github/CODEOWNERS

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Lib/ast.py @isidentical
135135

136136
**/*idlelib* @terryjreedy
137137

138-
**/*typing* @gvanrossum @Fidget-Spinner @JelleZijlstra
138+
**/*typing* @gvanrossum @Fidget-Spinner @JelleZijlstra @AlexWaygood
139139

140140
**/*asyncore @giampaolo
141141
**/*asynchat @giampaolo

Doc/c-api/init.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1933,7 +1933,7 @@ is not possible due to its implementation being opaque at build time.
19331933
19341934
.. note::
19351935
A freed key becomes a dangling pointer. You should reset the key to
1936-
`NULL`.
1936+
``NULL``.
19371937
19381938
19391939
Methods

Doc/howto/logging-cookbook.rst

+65
Original file line numberDiff line numberDiff line change
@@ -3712,6 +3712,71 @@ Of course, the examples above show output according to the format used by
37123712
:func:`~logging.basicConfig`, but you can use a different formatter when you
37133713
configure logging.
37143714

3715+
Note that with the above scheme, you are somewhat at the mercy of buffering and
3716+
the sequence of write calls which you are intercepting. For example, with the
3717+
definition of ``LoggerWriter`` above, if you have the snippet
3718+
3719+
.. code-block:: python
3720+
3721+
sys.stderr = LoggerWriter(logger, logging.WARNING)
3722+
1 / 0
3723+
3724+
then running the script results in
3725+
3726+
.. code-block:: text
3727+
3728+
WARNING:demo:Traceback (most recent call last):
3729+
3730+
WARNING:demo: File "/home/runner/cookbook-loggerwriter/test.py", line 53, in <module>
3731+
3732+
WARNING:demo:
3733+
WARNING:demo:main()
3734+
WARNING:demo: File "/home/runner/cookbook-loggerwriter/test.py", line 49, in main
3735+
3736+
WARNING:demo:
3737+
WARNING:demo:1 / 0
3738+
WARNING:demo:ZeroDivisionError
3739+
WARNING:demo::
3740+
WARNING:demo:division by zero
3741+
3742+
As you can see, this output isn't ideal. That's because the underlying code
3743+
which writes to ``sys.stderr`` makes mutiple writes, each of which results in a
3744+
separate logged line (for example, the last three lines above). To get around
3745+
this problem, you need to buffer things and only output log lines when newlines
3746+
are seen. Let's use a slghtly better implementation of ``LoggerWriter``:
3747+
3748+
.. code-block:: python
3749+
3750+
class BufferingLoggerWriter(LoggerWriter):
3751+
def __init__(self, logger, level):
3752+
super().__init__(logger, level)
3753+
self.buffer = ''
3754+
3755+
def write(self, message):
3756+
if '\n' not in message:
3757+
self.buffer += message
3758+
else:
3759+
parts = message.split('\n')
3760+
if self.buffer:
3761+
s = self.buffer + parts.pop(0)
3762+
self.logger.log(self.level, s)
3763+
self.buffer = parts.pop()
3764+
for part in parts:
3765+
self.logger.log(self.level, part)
3766+
3767+
This just buffers up stuff until a newline is seen, and then logs complete
3768+
lines. With this approach, you get better output:
3769+
3770+
.. code-block:: text
3771+
3772+
WARNING:demo:Traceback (most recent call last):
3773+
WARNING:demo: File "/home/runner/cookbook-loggerwriter/main.py", line 55, in <module>
3774+
WARNING:demo: main()
3775+
WARNING:demo: File "/home/runner/cookbook-loggerwriter/main.py", line 52, in main
3776+
WARNING:demo: 1/0
3777+
WARNING:demo:ZeroDivisionError: division by zero
3778+
3779+
37153780
.. patterns-to-avoid:
37163781
37173782
Patterns to avoid

Doc/library/asyncio-api-index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ await on multiple things with timeouts.
5757
- Monitor for completion.
5858

5959
* - :func:`timeout`
60-
- Run with a timeout. Useful in cases when `wait_for` is not suitable.
60+
- Run with a timeout. Useful in cases when ``wait_for`` is not suitable.
6161

6262
* - :func:`to_thread`
6363
- Asynchronously run a function in a separate OS thread.

Doc/library/importlib.metadata.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ all the metadata in a JSON-compatible form per :PEP:`566`::
211211
The actual type of the object returned by ``metadata()`` is an
212212
implementation detail and should be accessed only through the interface
213213
described by the
214-
`PackageMetadata protocol <https://importlib-metadata.readthedocs.io/en/latest/api.html#importlib_metadata.PackageMetadata>`.
214+
`PackageMetadata protocol <https://importlib-metadata.readthedocs.io/en/latest/api.html#importlib_metadata.PackageMetadata>`_.
215215

216216
.. versionchanged:: 3.10
217217
The ``Description`` is now included in the metadata when presented

0 commit comments

Comments
 (0)