From 67201ad53ff11576c69a9b762540b77128285f8d Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Mon, 23 Sep 2024 14:14:33 -0700 Subject: [PATCH 01/69] GH-65961: Document the deprecation of `__package__` and `__cached__` (GH-124377) The code changes for warning related to `__package__` landed in Python 3.12. `__cached__` doesn't have any changes as it isn't used but only set by the import system. --- Doc/deprecations/pending-removal-in-3.14.rst | 3 --- Doc/deprecations/pending-removal-in-3.15.rst | 3 +++ Doc/library/importlib.rst | 4 ++-- Doc/reference/import.rst | 8 ++++++++ .../2024-09-23-13-25-27.gh-issue-65961.LDqXV2.rst | 1 + 5 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2024-09-23-13-25-27.gh-issue-65961.LDqXV2.rst diff --git a/Doc/deprecations/pending-removal-in-3.14.rst b/Doc/deprecations/pending-removal-in-3.14.rst index 6c831ae366ced5..452d6643e1d146 100644 --- a/Doc/deprecations/pending-removal-in-3.14.rst +++ b/Doc/deprecations/pending-removal-in-3.14.rst @@ -47,9 +47,6 @@ Pending Removal in Python 3.14 * :mod:`email`: Deprecated the *isdst* parameter in :func:`email.utils.localtime`. (Contributed by Alan Williams in :gh:`72346`.) -* :mod:`importlib`: ``__package__`` and ``__cached__`` will cease to be set or - taken into consideration by the import system (:gh:`97879`). - * :mod:`importlib.abc` deprecated classes: * :class:`!importlib.abc.ResourceReader` diff --git a/Doc/deprecations/pending-removal-in-3.15.rst b/Doc/deprecations/pending-removal-in-3.15.rst index f7145a85bd2994..b921b4f97d524e 100644 --- a/Doc/deprecations/pending-removal-in-3.15.rst +++ b/Doc/deprecations/pending-removal-in-3.15.rst @@ -17,6 +17,9 @@ Pending Removal in Python 3.15 * The :option:`!--cgi` flag to the :program:`python -m http.server` command-line interface has been deprecated since Python 3.13. +* :mod:`importlib`: ``__package__`` and ``__cached__`` will cease to be set or + taken into consideration by the import system (:gh:`97879`). + * :class:`locale`: * The :func:`~locale.getdefaultlocale` function diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst index d0a3d9d578e0cd..e4cef1f3e3b7c0 100644 --- a/Doc/library/importlib.rst +++ b/Doc/library/importlib.rst @@ -1237,8 +1237,8 @@ find and load modules. .. attribute:: has_location ``True`` if the spec's :attr:`origin` refers to a loadable location, - ``False`` otherwise. This value impacts how :attr:`origin` is interpreted - and how the module's :attr:`__file__` is populated. + ``False`` otherwise. This value impacts how :attr:`origin` is interpreted + and how the module's :attr:`__file__` is populated. .. class:: AppleFrameworkLoader(name, path) diff --git a/Doc/reference/import.rst b/Doc/reference/import.rst index 7de995b12702ec..19b8aa05072c73 100644 --- a/Doc/reference/import.rst +++ b/Doc/reference/import.rst @@ -596,6 +596,10 @@ listed below. Raise :exc:`DeprecationWarning` instead of :exc:`ImportWarning` when falling back to ``__package__``. + .. deprecated-removed:: 3.13 3.15 + ``__package__`` will cease to be set or taken into consideration + by the import system or standard library. + .. attribute:: __spec__ @@ -653,6 +657,10 @@ listed below. It is **strongly** recommended that you rely on :attr:`__spec__` instead of ``__cached__``. + .. deprecated-removed:: 3.13 3.15 + ``__cached__`` will cease to be set or taken into consideration + by the import system or standard library. + .. _package-path-rules: module.__path__ diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-09-23-13-25-27.gh-issue-65961.LDqXV2.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-09-23-13-25-27.gh-issue-65961.LDqXV2.rst new file mode 100644 index 00000000000000..d380027f3c5776 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2024-09-23-13-25-27.gh-issue-65961.LDqXV2.rst @@ -0,0 +1 @@ +Deprecate the setting and using ``__package__`` and ``__cached__``. From 0060486862bfa8e6583beb627be154daaaaa9e2a Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Mon, 23 Sep 2024 23:11:34 +0100 Subject: [PATCH 02/69] Doc: Add ``make dist-no-html`` (#124383) Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- Doc/Makefile | 32 ++++++++++++++++++++++++++++++- Doc/tools/templates/download.html | 2 +- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Doc/Makefile b/Doc/Makefile index fc0d1e4d9a2a55..a2d89343648dc1 100644 --- a/Doc/Makefile +++ b/Doc/Makefile @@ -182,13 +182,26 @@ venv: echo "The venv has been created in the $(VENVDIR) directory"; \ fi +.PHONY: dist-no-html +dist-no-html: dist-text dist-pdf dist-epub dist-texinfo + .PHONY: dist dist: rm -rf dist mkdir -p dist - + $(MAKE) dist-html + $(MAKE) dist-text + $(MAKE) dist-pdf + $(MAKE) dist-epub + $(MAKE) dist-texinfo + +.PHONY: dist-html +dist-html: # archive the HTML @echo "Building HTML..." + mkdir -p dist + rm -rf build/html + find dist -name 'python-$(DISTVERSION)-docs-html*' -exec rm -rf {} \; $(MAKE) html cp -pPR build/html dist/python-$(DISTVERSION)-docs-html tar -C dist -cf dist/python-$(DISTVERSION)-docs-html.tar python-$(DISTVERSION)-docs-html @@ -198,8 +211,13 @@ dist: rm dist/python-$(DISTVERSION)-docs-html.tar @echo "Build finished and archived!" +.PHONY: dist-text +dist-text: # archive the text build @echo "Building text..." + mkdir -p dist + rm -rf build/text + find dist -name 'python-$(DISTVERSION)-docs-text*' -exec rm -rf {} \; $(MAKE) text cp -pPR build/text dist/python-$(DISTVERSION)-docs-text tar -C dist -cf dist/python-$(DISTVERSION)-docs-text.tar python-$(DISTVERSION)-docs-text @@ -209,9 +227,13 @@ dist: rm dist/python-$(DISTVERSION)-docs-text.tar @echo "Build finished and archived!" +.PHONY: dist-pdf +dist-pdf: # archive the A4 latex @echo "Building LaTeX (A4 paper)..." + mkdir -p dist rm -rf build/latex + find dist -name 'python-$(DISTVERSION)-docs-pdf*' -exec rm -rf {} \; $(MAKE) latex PAPER=a4 # remove zip & bz2 dependency on all-pdf, # as otherwise the full latexmk process is run twice. @@ -222,16 +244,24 @@ dist: cp build/latex/docs-pdf.tar.bz2 dist/python-$(DISTVERSION)-docs-pdf-a4.tar.bz2 @echo "Build finished and archived!" +.PHONY: dist-epub +dist-epub: # copy the epub build @echo "Building EPUB..." + mkdir -p dist rm -rf build/epub + rm -f dist/python-$(DISTVERSION)-docs.epub $(MAKE) epub cp -pPR build/epub/Python.epub dist/python-$(DISTVERSION)-docs.epub @echo "Build finished and archived!" +.PHONY: dist-texinfo +dist-texinfo: # archive the texinfo build @echo "Building Texinfo..." + mkdir -p dist rm -rf build/texinfo + find dist -name 'python-$(DISTVERSION)-docs-texinfo*' -exec rm -rf {} \; $(MAKE) texinfo $(MAKE) info --directory=build/texinfo cp -pPR build/texinfo dist/python-$(DISTVERSION)-docs-texinfo diff --git a/Doc/tools/templates/download.html b/Doc/tools/templates/download.html index f69adc71f937c4..b4217908cc63c9 100644 --- a/Doc/tools/templates/download.html +++ b/Doc/tools/templates/download.html @@ -7,7 +7,7 @@ The link below returns HTTP 404 until the first related alpha release. This is expected; use daily documentation builds for CPython development. #} - {% set dlbase = 'https://docs.python.org/ftp/python/doc/' + release %} + {% set dlbase = 'https://www.python.org/ftp/python/doc/' + release %} {% endif %} {% block body %} From 8a2baedc4bcb606da937e4e066b4b3a18961cace Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 23 Sep 2024 15:19:35 -0700 Subject: [PATCH 03/69] Bump Ruff to 0.6.7 (#124384) --- .pre-commit-config.yaml | 2 +- Doc/tools/extensions/c_annotations.py | 5 +---- Lib/test/pickletester.py | 4 +++- Lib/test/test_bz2.py | 1 - Lib/test/test_contextlib.py | 2 -- Lib/test/test_io.py | 2 -- Lib/test/test_os.py | 3 ++- Lib/test/test_with.py | 6 ++++-- 8 files changed, 11 insertions(+), 14 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1ce4cb81511d8e..4cdb7545454589 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.4.10 + rev: v0.6.7 hooks: - id: ruff name: Run Ruff (lint) on Doc/ diff --git a/Doc/tools/extensions/c_annotations.py b/Doc/tools/extensions/c_annotations.py index a65cf71e4affe3..50065d34a2c27a 100644 --- a/Doc/tools/extensions/c_annotations.py +++ b/Doc/tools/extensions/c_annotations.py @@ -124,10 +124,7 @@ def add_annotations(app: Sphinx, doctree: nodes.document) -> None: continue if not par[0].get("ids", None): continue - name = par[0]["ids"][0] - if name.startswith("c."): - name = name[2:] - + name = par[0]["ids"][0].removeprefix("c.") objtype = par["objtype"] # Stable ABI annotation. diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index 334d4dfebdf893..1722cc8612ca6b 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -4345,7 +4345,9 @@ class MyIntWithNew2(MyIntWithNew): class SlotList(MyList): __slots__ = ["foo"] -class SimpleNewObj(int): +# Ruff "redefined while unused" false positive here due to `global` variables +# being assigned (and then restored) from within test methods earlier in the file +class SimpleNewObj(int): # noqa: F811 def __init__(self, *args, **kwargs): # raise an error, to make sure this isn't called raise TypeError("SimpleNewObj.__init__() didn't expect to get called") diff --git a/Lib/test/test_bz2.py b/Lib/test/test_bz2.py index e4d1381be5f340..7d786be1d25b1c 100644 --- a/Lib/test/test_bz2.py +++ b/Lib/test/test_bz2.py @@ -476,7 +476,6 @@ def testReadlinesNoNewline(self): self.assertEqual(xlines, [b'Test']) def testContextProtocol(self): - f = None with BZ2File(self.filename, "wb") as f: f.write(b"xxx") f = BZ2File(self.filename, "rb") diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py index 36c3abca80f894..cf6519598037e9 100644 --- a/Lib/test/test_contextlib.py +++ b/Lib/test/test_contextlib.py @@ -444,12 +444,10 @@ class FileContextTestCase(unittest.TestCase): def testWithOpen(self): tfn = tempfile.mktemp() try: - f = None with open(tfn, "w", encoding="utf-8") as f: self.assertFalse(f.closed) f.write("Booh\n") self.assertTrue(f.closed) - f = None with self.assertRaises(ZeroDivisionError): with open(tfn, "r", encoding="utf-8") as f: self.assertFalse(f.closed) diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 1ca3edac8c8dc9..aa1b8268592ff7 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -639,11 +639,9 @@ def test_large_file_ops(self): def test_with_open(self): for bufsize in (0, 100): - f = None with self.open(os_helper.TESTFN, "wb", bufsize) as f: f.write(b"xxx") self.assertEqual(f.closed, True) - f = None try: with self.open(os_helper.TESTFN, "wb", bufsize) as f: 1/0 diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 9fa4e406bd2468..307f0f11ddc33f 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -3177,7 +3177,8 @@ class Win32NtTests(unittest.TestCase): def test_getfinalpathname_handles(self): nt = import_helper.import_module('nt') ctypes = import_helper.import_module('ctypes') - import ctypes.wintypes + # Ruff false positive -- it thinks we're redefining `ctypes` here + import ctypes.wintypes # noqa: F811 kernel = ctypes.WinDLL('Kernel32.dll', use_last_error=True) kernel.GetCurrentProcess.restype = ctypes.wintypes.HANDLE diff --git a/Lib/test/test_with.py b/Lib/test/test_with.py index e8c4ddf979e2ee..839cdec68d573e 100644 --- a/Lib/test/test_with.py +++ b/Lib/test/test_with.py @@ -171,7 +171,10 @@ def __exit__(self, *args): def shouldThrow(): ct = EnterThrows() self.foo = None - with ct as self.foo: + # Ruff complains that we're redefining `self.foo` here, + # but the whole point of the test is to check that `self.foo` + # is *not* redefined (because `__enter__` raises) + with ct as self.foo: # ruff: noqa: F811 pass self.assertRaises(RuntimeError, shouldThrow) self.assertEqual(self.foo, None) @@ -252,7 +255,6 @@ def testInlineGeneratorBoundSyntax(self): self.assertAfterWithGeneratorInvariantsNoError(foo) def testInlineGeneratorBoundToExistingVariable(self): - foo = None with mock_contextmanager_generator() as foo: self.assertInWithGeneratorInvariants(foo) self.assertAfterWithGeneratorInvariantsNoError(foo) From 27a62e7371f062a80704f6bf4d6e8f06568d37aa Mon Sep 17 00:00:00 2001 From: Wulian <1055917385@qq.com> Date: Tue, 24 Sep 2024 07:09:22 +0800 Subject: [PATCH 04/69] gh-124102: Update internal PCbuild docs to accurately list build dependencies (GH-124103) --- ...-09-16-09-42-05.gh-issue-124102.Ow254j.rst | 2 ++ PCbuild/build.bat | 2 +- PCbuild/env.bat | 11 ++++----- PCbuild/find_msbuild.bat | 10 -------- PCbuild/get_externals.bat | 2 +- PCbuild/python.props | 6 +---- PCbuild/pythoncore.vcxproj | 2 +- PCbuild/readme.txt | 8 +++---- PCbuild/tcltk.props | 3 --- Tools/msi/README.txt | 24 +++++++------------ Tools/msi/bundle/bootstrap/pythonba.vcxproj | 3 --- 11 files changed, 24 insertions(+), 49 deletions(-) create mode 100644 Misc/NEWS.d/next/Build/2024-09-16-09-42-05.gh-issue-124102.Ow254j.rst diff --git a/Misc/NEWS.d/next/Build/2024-09-16-09-42-05.gh-issue-124102.Ow254j.rst b/Misc/NEWS.d/next/Build/2024-09-16-09-42-05.gh-issue-124102.Ow254j.rst new file mode 100644 index 00000000000000..6edc9a6abbced4 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2024-09-16-09-42-05.gh-issue-124102.Ow254j.rst @@ -0,0 +1,2 @@ +Update internal documentation under PCbuild, so it now correctly states that +Windows requires VS2017 or later and Python 3.10 or later diff --git a/PCbuild/build.bat b/PCbuild/build.bat index 6c76f09a071312..abe649553756a7 100644 --- a/PCbuild/build.bat +++ b/PCbuild/build.bat @@ -8,7 +8,7 @@ echo.version(s) of Microsoft Visual Studio to be installed (see readme.txt). echo. echo.After the flags recognized by this script, up to 9 arguments to be passed echo.directly to MSBuild may be passed. If the argument contains an '=', the -echo.entire argument must be quoted (e.g. `%~nx0 "/p:PlatformToolset=v100"`). +echo.entire argument must be quoted (e.g. `%~nx0 "/p:PlatformToolset=v141"`). echo.Alternatively you can put extra flags for MSBuild in a file named echo.`msbuild.rsp` in the `PCbuild` directory, one flag per line. This file echo.will be picked automatically by MSBuild. Flags put in this file does not diff --git a/PCbuild/env.bat b/PCbuild/env.bat index 2820e304582cff..cf4638b7aa63a7 100644 --- a/PCbuild/env.bat +++ b/PCbuild/env.bat @@ -4,8 +4,8 @@ rem command window. However, most builds of Python will ignore the version rem of the tools on PATH and use PlatformToolset instead. Ideally, both sets of rem tools should be the same version to avoid potential conflicts. rem -rem To build Python with an earlier toolset, pass "/p:PlatformToolset=v100" (or -rem 'v110', 'v120' or 'v140') to the build script. +rem To build Python with an earlier toolset, pass "/p:PlatformToolset=v141" (or +rem 'v142', 'v143') to the build script. echo Build environments: x86, amd64, x86_amd64 echo. @@ -20,8 +20,7 @@ call "%VSTOOLS%" %_ARGS% exit /B 0 :skip_vswhere -if not defined VSTOOLS set VSTOOLS=%VS140COMNTOOLS% -if not defined VSTOOLS set VSTOOLS=%VS120COMNTOOLS% -if not defined VSTOOLS set VSTOOLS=%VS110COMNTOOLS% -if not defined VSTOOLS set VSTOOLS=%VS100COMNTOOLS% +if not defined VSTOOLS set VSTOOLS=%VS143COMNTOOLS% +if not defined VSTOOLS set VSTOOLS=%VS142COMNTOOLS% +if not defined VSTOOLS set VSTOOLS=%VS141COMNTOOLS% call "%VSTOOLS%..\..\VC\vcvarsall.bat" %_ARGS% diff --git a/PCbuild/find_msbuild.bat b/PCbuild/find_msbuild.bat index ce7e71efa31f6c..82dd34beede6ee 100644 --- a/PCbuild/find_msbuild.bat +++ b/PCbuild/find_msbuild.bat @@ -39,16 +39,6 @@ @if defined MSBUILD @if exist %MSBUILD% (set _Py_MSBuild_Source=Visual Studio installation) & goto :found :skip_vswhere -@rem VS 2015 and earlier register MSBuild separately, so we can find it. -@reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\14.0" /v MSBuildToolsPath /reg:32 >nul 2>nul -@if NOT ERRORLEVEL 1 @for /F "tokens=1,2*" %%i in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\14.0" /v MSBuildToolsPath /reg:32') DO @( - @if "%%i"=="MSBuildToolsPath" @if exist "%%k\msbuild.exe" @(set MSBUILD="%%k\msbuild.exe") -) -@if exist %MSBUILD% (set _Py_MSBuild_Source=registry) & goto :found - - -@exit /b 1 - :found @pushd %MSBUILD% >nul 2>nul @if not ERRORLEVEL 1 @( diff --git a/PCbuild/get_externals.bat b/PCbuild/get_externals.bat index a1a67966182863..137c94789e1809 100644 --- a/PCbuild/get_externals.bat +++ b/PCbuild/get_externals.bat @@ -45,7 +45,7 @@ if "%ORG%"=="" (set ORG=python) call "%PCBUILD%\find_python.bat" "%PYTHON%" if NOT DEFINED PYTHON ( - where /Q git || echo Python 3.6 could not be found or installed, and git.exe is not on your PATH && exit /B 1 + where /Q git || echo Python 3.10 or later could not be found or installed, and git.exe is not on your PATH && exit /B 1 ) echo.Fetching external libraries... diff --git a/PCbuild/python.props b/PCbuild/python.props index c8ecdb4515ae9a..6e90178f4ea8ab 100644 --- a/PCbuild/python.props +++ b/PCbuild/python.props @@ -6,7 +6,7 @@ Release