Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 70f1db9

Browse files
committed
Merge remote-tracking branch 'origin/main' into gh-74929-pep-667-general-docs-update
2 parents a867005 + 1726902 commit 70f1db9

Some content is hidden

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

42 files changed

+1181
-148
lines changed

.github/workflows/reusable-docs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ jobs:
6262
python Doc/tools/check-warnings.py \
6363
--annotate-diff '${{ env.branch_base }}' '${{ env.branch_pr }}' \
6464
--fail-if-regression \
65-
--fail-if-improved
65+
--fail-if-improved \
66+
--fail-if-new-news-nit
6667
6768
# This build doesn't use problem matchers or check annotations
6869
build_doc_oldest_supported_sphinx:

Doc/library/dataclasses.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,8 @@ methods will raise a :exc:`FrozenInstanceError` when invoked.
616616
There is a tiny performance penalty when using ``frozen=True``:
617617
:meth:`~object.__init__` cannot use simple assignment to initialize fields, and
618618
must use :meth:`!object.__setattr__`.
619-
.. Make sure to not remove "object" from "object.__setattr__" in the above markup
619+
620+
.. Make sure to not remove "object" from "object.__setattr__" in the above markup!
620621
621622
.. _dataclasses-inheritance:
622623

Doc/library/functions.rst

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,9 +614,19 @@ are always available. They are listed here in alphabetical order.
614614
will be used for both the global and the local variables. If *globals* and
615615
*locals* are given, they are used for the global and local variables,
616616
respectively. If provided, *locals* can be any mapping object. Remember
617-
that at the module level, globals and locals are the same dictionary. If
618-
``exec`` gets two separate objects as *globals* and *locals*, the code will
619-
be executed as if it were embedded in a class definition.
617+
that at the module level, globals and locals are the same dictionary.
618+
619+
.. note::
620+
621+
When ``exec`` gets two separate objects as *globals* and *locals*, the
622+
code will be executed as if it were embedded in a class definition. This
623+
means functions defined in the executed code will not be able to access
624+
variables assigned at the top level (as the "top level" variables are
625+
treated as class variables in a class definition).
626+
Passing a :class:`collections.ChainMap` instance as *globals* allows name
627+
lookups to be chained across multiple mappings without triggering this
628+
behaviour. Values assigned to top-level names in the executed code can be
629+
retrieved by passing an empty dictionary as the first entry in the chain.
620630

621631
If the *globals* dictionary does not contain a value for the key
622632
``__builtins__``, a reference to the dictionary of the built-in module

Doc/library/typing.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,7 @@ without the dedicated syntax, as documented below.
17801780

17811781
.. _typevartuple:
17821782

1783-
.. class:: TypeVarTuple(name, default=typing.NoDefault)
1783+
.. class:: TypeVarTuple(name, *, default=typing.NoDefault)
17841784

17851785
Type variable tuple. A specialized form of :ref:`type variable <typevar>`
17861786
that enables *variadic* generics.
@@ -2546,7 +2546,7 @@ types.
25462546
``__required_keys__`` and ``__optional_keys__`` rely on may not work
25472547
properly, and the values of the attributes may be incorrect.
25482548

2549-
Support for :data:`ReadOnly` is reflected in the following attributes::
2549+
Support for :data:`ReadOnly` is reflected in the following attributes:
25502550

25512551
.. attribute:: __readonly_keys__
25522552

Doc/library/unittest.mock.rst

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -414,13 +414,13 @@ the *new_callable* argument to :func:`patch`.
414414

415415
This can be useful where you want to make a series of assertions that
416416
reuse the same object. Note that :meth:`reset_mock` *doesn't* clear the
417-
return value, :attr:`side_effect` or any child attributes you have
417+
:attr:`return_value`, :attr:`side_effect` or any child attributes you have
418418
set using normal assignment by default. In case you want to reset
419-
*return_value* or :attr:`side_effect`, then pass the corresponding
419+
:attr:`return_value` or :attr:`side_effect`, then pass the corresponding
420420
parameter as ``True``. Child mocks and the return value mock
421421
(if any) are reset as well.
422422

423-
.. note:: *return_value*, and :attr:`side_effect` are keyword-only
423+
.. note:: *return_value*, and *side_effect* are keyword-only
424424
arguments.
425425

426426

@@ -2584,40 +2584,16 @@ called incorrectly.
25842584

25852585
Before I explain how auto-speccing works, here's why it is needed.
25862586

2587-
:class:`Mock` is a very powerful and flexible object, but it suffers from two flaws
2588-
when used to mock out objects from a system under test. One of these flaws is
2589-
specific to the :class:`Mock` api and the other is a more general problem with using
2590-
mock objects.
2587+
:class:`Mock` is a very powerful and flexible object, but it suffers from a flaw which
2588+
is general to mocking. If you refactor some of your code, rename members and so on, any
2589+
tests for code that is still using the *old api* but uses mocks instead of the real
2590+
objects will still pass. This means your tests can all pass even though your code is
2591+
broken.
25912592

2592-
First the problem specific to :class:`Mock`. :class:`Mock` has two assert methods that are
2593-
extremely handy: :meth:`~Mock.assert_called_with` and
2594-
:meth:`~Mock.assert_called_once_with`.
2593+
.. versionchanged:: 3.5
25952594

2596-
>>> mock = Mock(name='Thing', return_value=None)
2597-
>>> mock(1, 2, 3)
2598-
>>> mock.assert_called_once_with(1, 2, 3)
2599-
>>> mock(1, 2, 3)
2600-
>>> mock.assert_called_once_with(1, 2, 3)
2601-
Traceback (most recent call last):
2602-
...
2603-
AssertionError: Expected 'mock' to be called once. Called 2 times.
2604-
2605-
Because mocks auto-create attributes on demand, and allow you to call them
2606-
with arbitrary arguments, if you misspell one of these assert methods then
2607-
your assertion is gone:
2608-
2609-
.. code-block:: pycon
2610-
2611-
>>> mock = Mock(name='Thing', return_value=None)
2612-
>>> mock(1, 2, 3)
2613-
>>> mock.assret_called_once_with(4, 5, 6) # Intentional typo!
2614-
2615-
Your tests can pass silently and incorrectly because of the typo.
2616-
2617-
The second issue is more general to mocking. If you refactor some of your
2618-
code, rename members and so on, any tests for code that is still using the
2619-
*old api* but uses mocks instead of the real objects will still pass. This
2620-
means your tests can all pass even though your code is broken.
2595+
Before 3.5, tests with a typo in the word assert would silently pass when they should
2596+
raise an error. You can still achieve this behavior by passing ``unsafe=True`` to Mock.
26212597

26222598
Note that this is another reason why you need integration tests as well as
26232599
unit tests. Testing everything in isolation is all fine and dandy, but if you

Doc/tools/check-warnings.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
from pathlib import Path
1414
from typing import TextIO
1515

16+
# Fail if NEWS nit found before this line number
17+
NEWS_NIT_THRESHOLD = 200
18+
1619
# Exclude these whether they're dirty or clean,
1720
# because they trigger a rebuild of dirty files.
1821
EXCLUDE_FILES = {
@@ -245,6 +248,32 @@ def fail_if_improved(
245248
return 0
246249

247250

251+
def fail_if_new_news_nit(warnings: list[str], threshold: int) -> int:
252+
"""
253+
Ensure no warnings are found in the NEWS file before a given line number.
254+
"""
255+
news_nits = (
256+
warning
257+
for warning in warnings
258+
if "/build/NEWS:" in warning
259+
)
260+
261+
# Nits found before the threshold line
262+
new_news_nits = [
263+
nit
264+
for nit in news_nits
265+
if int(nit.split(":")[1]) <= threshold
266+
]
267+
268+
if new_news_nits:
269+
print("\nError: new NEWS nits:\n")
270+
for warning in new_news_nits:
271+
print(warning)
272+
return -1
273+
274+
return 0
275+
276+
248277
def main(argv: list[str] | None = None) -> int:
249278
parser = argparse.ArgumentParser()
250279
parser.add_argument(
@@ -264,6 +293,14 @@ def main(argv: list[str] | None = None) -> int:
264293
action="store_true",
265294
help="Fail if new files with no nits are found",
266295
)
296+
parser.add_argument(
297+
"--fail-if-new-news-nit",
298+
metavar="threshold",
299+
type=int,
300+
nargs="?",
301+
const=NEWS_NIT_THRESHOLD,
302+
help="Fail if new NEWS nit found before threshold line number",
303+
)
267304

268305
args = parser.parse_args(argv)
269306
if args.annotate_diff is not None and len(args.annotate_diff) > 2:
@@ -304,6 +341,9 @@ def main(argv: list[str] | None = None) -> int:
304341
if args.fail_if_improved:
305342
exit_code += fail_if_improved(files_with_expected_nits, files_with_nits)
306343

344+
if args.fail_if_new_news_nit:
345+
exit_code += fail_if_new_news_nit(warnings, args.fail_if_new_news_nit)
346+
307347
return exit_code
308348

309349

Doc/using/cmdline.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,15 @@ Miscellaneous options
290290

291291
.. option:: -i
292292

293-
When a script is passed as first argument or the :option:`-c` option is used,
294-
enter interactive mode after executing the script or the command, even when
295-
:data:`sys.stdin` does not appear to be a terminal. The
293+
Enter interactive mode after execution.
294+
295+
Using the :option:`-i` option will enter interactive mode in any of the following circumstances\:
296+
297+
* When a script is passed as first argument
298+
* When the :option:`-c` option is used
299+
* When the :option:`-m` option is used
300+
301+
Interactive mode will start even when :data:`sys.stdin` does not appear to be a terminal. The
296302
:envvar:`PYTHONSTARTUP` file is not read.
297303

298304
This can be useful to inspect global variables or a stack trace when a script

Doc/whatsnew/3.13.rst

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2204,16 +2204,6 @@ Changes in the Python API
22042204
returned by :meth:`zipfile.ZipFile.open` was changed from ``'r'`` to ``'rb'``.
22052205
(Contributed by Serhiy Storchaka in :gh:`115961`.)
22062206

2207-
* Callbacks registered in the :mod:`tkinter` module now take arguments as
2208-
various Python objects (``int``, ``float``, ``bytes``, ``tuple``),
2209-
not just ``str``.
2210-
To restore the previous behavior set :mod:`!tkinter` module global
2211-
:data:`!wantobject` to ``1`` before creating the
2212-
:class:`!Tk` object or call the :meth:`!wantobject`
2213-
method of the :class:`!Tk` object with argument ``1``.
2214-
Calling it with argument ``2`` restores the current default behavior.
2215-
(Contributed by Serhiy Storchaka in :gh:`66410`.)
2216-
22172207
* Calling :func:`locals` in an :term:`optimised scope` now produces an
22182208
independent snapshot on each call, and hence no longer implicitly updates
22192209
previously returned references. Obtaining the legacy CPython behaviour now

Lib/_ios_support.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
# ctypes is an optional module. If it's not present, we're limited in what
66
# we can tell about the system, but we don't want to prevent the module
77
# from working.
8-
print("ctypes isn't available; iOS system calls will not be available")
8+
print("ctypes isn't available; iOS system calls will not be available", file=sys.stderr)
99
objc = None
1010
else:
1111
# ctypes is available. Load the ObjC library, and wrap the objc_getClass,
1212
# sel_registerName methods
1313
lib = util.find_library("objc")
1414
if lib is None:
1515
# Failed to load the objc library
16-
raise RuntimeError("ObjC runtime library couldn't be loaded")
16+
raise ImportError("ObjC runtime library couldn't be loaded")
1717

1818
objc = cdll.LoadLibrary(lib)
1919
objc.objc_getClass.restype = c_void_p

Lib/_pyrepl/commands.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@
3434

3535
# types
3636
if False:
37-
from .reader import Reader
3837
from .historical_reader import HistoricalReader
39-
from .console import Event
4038

4139

4240
class Command:
@@ -245,7 +243,7 @@ def do(self) -> None:
245243
x, y = r.pos2xy()
246244
new_y = y - 1
247245

248-
if new_y < 0:
246+
if r.bol() == 0:
249247
if r.historyi > 0:
250248
r.select_item(r.historyi - 1)
251249
return

Lib/_pyrepl/mypy.ini

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,15 @@ platform = linux
1010
pretty = True
1111

1212
# Enable most stricter settings
13-
enable_error_code = ignore-without-code
13+
enable_error_code = ignore-without-code,redundant-expr
1414
strict = True
1515

1616
# Various stricter settings that we can't yet enable
1717
# Try to enable these in the following order:
18-
disallow_any_generics = False
1918
disallow_untyped_calls = False
2019
disallow_untyped_defs = False
2120
check_untyped_defs = False
2221

23-
disable_error_code = return
24-
2522
# Various internal modules that typeshed deliberately doesn't have stubs for:
2623
[mypy-_abc.*,_opcode.*,_overlapped.*,_testcapi.*,_testinternalcapi.*,test.*]
2724
ignore_missing_imports = True

Lib/_pyrepl/pager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def get_pager() -> Pager:
3535
if os.environ.get('TERM') in ('dumb', 'emacs'):
3636
return plain_pager
3737
if sys.platform == 'win32':
38-
return lambda text, title='': tempfilepager(plain(text), 'more <')
38+
return lambda text, title='': tempfile_pager(plain(text), 'more <')
3939
if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0:
4040
return lambda text, title='': pipe_pager(text, 'less', title)
4141

Lib/asyncio/staggered.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ async def staggered_race(coro_fns, delay, *, loop=None):
6969
exceptions = []
7070
running_tasks = []
7171

72-
async def run_one_coro(
73-
previous_failed: typing.Optional[locks.Event]) -> None:
72+
async def run_one_coro(previous_failed) -> None:
7473
# Wait for the previous task to finish, or for delay seconds
7574
if previous_failed is not None:
7675
with contextlib.suppress(exceptions_mod.TimeoutError):

0 commit comments

Comments
 (0)