8000 Merge remote-tracking branch 'upstream/main' · python/cpython@c1069a4 · GitHub
[go: up one dir, main page]

Skip to content

Commit c1069a4

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents c7c4f8e + b465b60 commit c1069a4

26 files changed

+572
-566
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Mac/pythonw
7575
Misc/python.pc
7676
Misc/python-embed.pc
7777
Misc/python-config.sh
78+
Modules/Setup.bootstrap
7879
Modules/Setup.config
7980
Modules/Setup.local
8081
Modules/Setup.stdlib

Lib/distutils/tests/test_util.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,10 @@ def test_check_environ_getpwuid(self):
248248
util._environ_checked = 0
249249
os.environ.pop('HOME', None)
250250

251-
import pwd
251+
try:
252+
import pwd
253+
except ImportError:
254+
raise unittest.SkipTest("Test requires pwd module.")
252255

253256
# only set pw_dir field, other fields are not used
254257
result = pwd.struct_passwd((None, None, None, None, None,

Lib/posixpath.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,11 @@ def expanduser(path):
241241
i = len(path)
242242
if i == 1:
243243
if 'HOME' not in os.environ:
244-
import pwd
244+
try:
245+
import pwd
246+
except ImportError:
247+
# pwd module unavailable, return path unchanged
248+
return path
245249
try:
246250
userhome = pwd.getpwuid(os.getuid()).pw_dir
247251
except KeyError:
@@ -251,7 +255,11 @@ def expanduser(path):
251255
else:
252256
userhome = os.environ['HOME']
253257
else:
254-
import pwd
258+
try:
259+
import pwd
260+
except ImportError:
261+
# pwd module unavailable, return path unchanged
262+
return path
255263
name = path[1:i]
256264
if isinstance(name, bytes):
257265
name = str(name, 'ASCII')

Lib/test/test_pathlib.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,6 +1486,9 @@ def _test_home(self, p):
14861486
self.assertIs(type(p), type(q))
14871487
self.assertTrue(p.is_absolute())
14881488

1489+
@unittest.skipIf(
1490+
pwd is None, reason="Test requires pwd module to get homedir."
1491+
)
14891492
def test_home(self):
14901493
with os_helper.EnvironmentVarGuard() as env:
14911494
self._test_home(self.cls.home())

Lib/test/test_posix.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,18 @@
1515
import time
1616
import os
1717
import platform
18-
import pwd
1918
import stat
2019
import tempfile
2120
import unittest
2221
import warnings
2322
import textwrap
2423
from contextlib import contextmanager
2524

25+
try:
26+
import pwd
27+
except ImportError:
28+
pwd = None
29+
2630
_DUMMY_SYMLINK = os.path.join(tempfile.gettempdir(),
2731
os_helper.TESTFN + '-dummy-symlink')
2832

@@ -126,6 +130,7 @@ def test_setresgid_exception(self):
126130

127131
@unittest.skipUnless(hasattr(posix, 'initgroups'),
128132
"test needs os.initgroups()")
133+
@unittest.skipUnless(hasattr(pwd, 'getpwuid'), "test needs pwd.getpwuid()")
129134
def test_initgroups(self):
130135
# It takes a string and an integer; check that it raises a TypeError
131136
# for other argument lists.

Lib/test/test_typing.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from typing import ParamSpec, Concatenate, ParamSpecArgs, ParamSpecKwargs
3333
from typing import TypeGuard
3434
import abc
35+
import textwrap
3536
import typing
3637
import weakref
3738
import types
@@ -2156,6 +2157,45 @@ def barfoo(x: AT): ...
21562157
def barfoo2(x: CT): ...
21572158
self.assertIs(get_type_hints(barfoo2, globals(), locals())['x'], CT)
21582159

2160+
def test_generic_pep585_forward_ref(self):
2161+
# See https://bugs.python.org/issue41370
2162+
2163+
class C1:
2164+
a: list['C1']
2165+
self.assertEqual(
2166+
get_type_hints(C1, globals(), locals()),
2167+
{'a': list[C1]}
2168+
)
2169+
2170+
class C2:
2171+
a: dict['C1', list[List[list['C2']]]]
2172+
self.assertEqual(
2173+
get_type_hints(C2, globals(), locals()),
2174+
{'a': dict[C1, list[List[list[C2]]]]}
2175+
)
2176+
2177+
# Test stringified annotations
2178+
scope = {}
2179+
exec(textwrap.dedent('''
2180+
from __future__ import annotations
2181+
class C3:
2182+
a: List[list["C2"]]
2183+
'''), scope)
2184+
C3 = scope['C3']
2185+
self.assertEqual(C3.__annotations__['a'], "List[list['C2']]")
2186+
self.assertEqual(
2187+
get_type_hints(C3, globals(), locals()),
2188+
{'a': List[list[C2]]}
2189+
)
2190+
2191+
# Test recursive types
2192+
X = list["X"]
2193+
def f(x: X): ...
2194+
self.assertEqual(
2195+
get_type_hints(f, globals(), locals()),
2196+
{'x': list[list[ForwardRef('X')]]}
2197+
)
2198+
21592199
def test_extended_generic_rules_subclassing(self):
21602200
class T1(Tuple[T, KT]): ...
21612201
class T2(Tuple[T, ...]): ...
@@ -3556,15 +3596,15 @@ def foobar(x: list[ForwardRef('X')]): ...
35563596
BA = Tuple[Annotated[T, (1, 0)], ...]
35573597
def barfoo(x: BA): ...
35583598
self.assertEqual(get_type_hints(barfoo, globals(), locals())['x'], Tuple[T, ...])
3559-
self.assertIs(
3599+
self.assertEqual(
35603600
get_type_hints(barfoo, globals(), locals(), include_extras=True)['x'],
35613601
BA
35623602
)
35633603

35643604
BA = tuple[Annotated[T, (1, 0)], ...]
35653605
def barfoo(x: BA): ...
35663606
self.assertEqual(get_type_hints(barfoo, globals(), locals())['x'], tuple[T, ...])
3567-
self.assertIs(
3607+
self.assertEqual(
35683608
get_type_hints(barfoo, globals(), locals(), include_extras=True)['x'],
35693609
BA
35703610
)

Lib/typing.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,12 @@ def _eval_type(t, globalns, localns, recursive_guard=frozenset()):
336336
if isinstance(t, ForwardRef):
337337
return t._evaluate(globalns, localns, recursive_guard)
338338
if isinstance(t, (_GenericAlias, GenericAlias, types.UnionType)):
339+
if isinstance(t, GenericAlias):
340+
args = tuple(
341+
ForwardRef(arg) if isinstance(arg, str) else arg
342+
for arg in t.__args__
343+
)
344+
t = t.__origin__[args]
339345
ev_args = tuple(_eval_type(a, globalns, localns, recursive_guard) for a in t.__args__)
340346
if ev_args == t.__args__:
341347
return t

Makefile.pre.in

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,9 @@ Modules/Setup.local:
917917
@# Create empty Setup.local when file was deleted by user
918918
echo "# Edit this file for local setup changes" > $@
919919

920+
Modules/Setup.bootstrap: $(srcdir)/Modules/Setup.bootstrap.in config.status
921+
./config.status $@
922+
920923
Modules/Setup.stdlib: $(srcdir)/Modules/Setup.stdlib.in config.status
921924
./config.status $@
922925

@@ -925,13 +928,13 @@ Makefile Modules/config.c: Makefile.pre \
925928
$(MAKESETUP) \
926929
$(srcdir)/Modules/Setup \
927930
Modules/Setup.local \
928-
$(srcdir)/Modules/Setup.bootstrap \
931+
Modules/Setup.bootstrap \
929932
Modules/Setup.stdlib
930933
$(SHELL) $(MAKESETUP) -c $(srcdir)/Modules/config.c.in \
931934
-s Modules \
932935
Modules/Setup.local \
933936
@MODULES_SETUP_STDLIB@ \
934-
$(srcdir)/Modules/Setup.bootstrap \
937+
Modules/Setup.bootstrap \
935938
$(srcdir)/Modules/Setup
936939
@mv config.c Modules
937940
@echo "The Makefile was updated, you may need to re-run make."
@@ -2146,7 +2149,7 @@ libainstall: @DEF_MAKE_RULE@ python-config
21462149
$(INSTALL_DATA) $(srcdir)/Modules/config.c.in $(DESTDIR)$(LIBPL)/config.c.in
21472150
$(INSTALL_DATA) Makefile $(DESTDIR)$(LIBPL)/Makefile
21482151
$(INSTALL_DATA) $(srcdir)/Modules/Setup $(DESTDIR)$(LIBPL)/Setup
2149-
$(INSTALL_DATA) $(srcdir)/Modules/Setup.bootstrap $(DESTDIR)$(LIBPL)/Setup.bootstrap
2152+
$(INSTALL_DATA) Modules/Setup.bootstrap $(DESTDIR)$(LIBPL)/Setup.bootstrap
21502153
$(INSTALL_DATA) Modules/Setup.stdlib $(DESTDIR)$(LIBPL)/Setup.stdlib
21512154
$(INSTALL_DATA) Modules/Setup.local $(DESTDIR)$(LIBPL)/Setup.local
21522155
$(INSTALL_DATA) Misc/python.pc $(DESTDIR)$(LIBPC)/python-$(VERSION).pc
@@ -2381,8 +2384,9 @@ distclean: clobber
23812384
for file in $(srcdir)/Lib/test/data/* ; do \
23822385
if test "$$file" != "$(srcdir)/Lib/test/data/README"; then rm "$$file"; fi; \
23832386
done
2384-
-rm -f core Makefile Makefile.pre config.status Modules/Setup.local \
2385-
Modules/Setup.stdlib Modules/ld_so_aix Modules/python.exp Misc/python.pc \
2387+
-rm -f core Makefile Makefile.pre config.status Modules/Setup.local
2388+
Modules/Setup.bootstrap Modules/Setup.stdlib \
2389+
Modules/ld_so_aix Modules/python.exp Misc/python.pc \
23862390
Misc/python-embed.pc Misc/python-config.sh
23872391
-rm -f python*-gdb.py
23882392
# Issue #28258: set LC_ALL to avoid issues with Estonian locale.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:func:`typing.get_type_hints` now supports evaluating strings as forward references in :ref:`PEP 585 generic aliases <types-genericalias>`.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The :mod:`pwd` module is now optional. :func:`os.path.expanduser` returns the path when the :mod:`pwd` module is not available.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Prevent CVE-2022-26488 by ensuring the Add to PATH option in the Windows
2+
installer uses the correct path when being repaired.

Modules/Setup.bootstrap renamed to Modules/Setup.bootstrap.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ _stat _stat.c
3232
_symtable symtablemodule.c
3333

3434
# for systems without $HOME env, used by site._getuserbase()
35-
pwd pwdmodule.c
35+
@MODULE_PWD_TRUE@pwd pwdmodule.c

Tools/msi/appendpath/appendpath.wxs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<Product Id="*" Language="!(loc.LCID)" Name="!(loc.Title)" Version="$(var.Version)" Manufacturer="!(loc.Manufacturer)" UpgradeCode="$(var.UpgradeCode)">
44
<Package InstallerVersion="500" Compressed="yes" InstallScope="perUser" />
55

6+
<PropertyRef Id="DetectTargetDir" />
67
<PropertyRef Id="UpgradeTable" />
78
<PropertyRef Id="REGISTRYKEY" />
89

Tools/msi/bundle/bundle.wxs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@
108108
<PackageGroupRef Id="crt" />
109109
<?endif ?>
110110
<PackageGroupRef Id="core" />
111-
<PackageGroupRef Id="dev" />
112111
<PackageGroupRef Id="exe" />
112+
<PackageGroupRef Id="dev" />
113113
<PackageGroupRef Id="lib" />
114114
<PackageGroupRef Id="test" />
115115
<PackageGroupRef Id="doc" />

Tools/msi/common.wxs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,23 @@
5353
</Fragment>
5454

5555
<Fragment>
56-
<?ifdef InstallDirectoryGuidSeed ?>
5756
<Directory Id="TARGETDIR" Name="SourceDir">
57+
<?ifdef InstallDirectoryGuidSeed ?>
5858
<Directory Id="InstallDirectory" ComponentGuidGenerationSeed="$(var.InstallDirectoryGuidSeed)" />
59+
<?endif ?>
5960
</Directory>
60-
<?endif ?>
61+
</Fragment>
62+
63+
<Fragment>
64+
<!-- Locate TARGETDIR automatically assuming we have executables installed -->
65+
<Property Id="TARGETDIR">
66+
<ComponentSearch Id="PythonExe_Directory" Guid="$(var.PythonExeComponentGuid)">
67+
<DirectorySearch Id="PythonExe_Directory" AssignToProperty="yes" Path=".">
68+
<FileSearch Id="PythonExe_DirectoryFile" Name="python.exe" />
69+
</DirectorySearch>
70+
</ComponentSearch>
71+
</Property>
72+
<Property Id="DetectTargetDir" Value="1" />
6173
</Fragment>
6274

6375
<!-- Top-level directories -->

Tools/msi/dev/dev.wxs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<Package InstallerVersion="500" Compressed="yes" InstallScope="perUser" />
55
<MediaTemplate EmbedCab="yes" CompressionLevel="high" />
66

7+
<PropertyRef Id="DetectTargetDir" />
78
<PropertyRef Id="UpgradeTable" />
89

910
<Feature Id="DefaultFeature" AllowAdvertise="no" Title="!(loc.Title)" Description="!(loc.Description)">

Tools/msi/doc/doc.wxs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<Package InstallerVersion="500" Compressed="yes" InstallScope="perUser" />
55
<MediaTemplate EmbedCab="yes" CompressionLevel="high" />
66

7+
<PropertyRef Id="DetectTargetDir" />
78
<PropertyRef Id="UpgradeTable" />
89
<PropertyRef Id="REGISTRYKEY" />
910

Tools/msi/lib/lib.wxs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<Package InstallerVersion="500" Compressed="yes" InstallScope="perUser" />
55
<MediaTemplate EmbedCab="yes" CompressionLevel="high" />
66

7+
<PropertyRef Id="DetectTargetDir" />
78
<PropertyRef Id="UpgradeTable" />
89
<PropertyRef Id="REGISTRYKEY" />
910

Tools/msi/path/path.wxs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
33
<Product Id="*" Language="!(loc.LCID)" Name="!(loc.Title)" Version="$(var.Version)" Manufacturer="!(loc.Manufacturer)" UpgradeCode="$(var.UpgradeCode)">
44
<Package InstallerVersion="500" Compressed="yes" InstallScope="perUser" />
5-
5+
6+
<PropertyRef Id="DetectTargetDir" />
67
<PropertyRef Id="UpgradeTable" />
78
<PropertyRef Id="REGISTRYKEY" />
89

Tools/msi/tcltk/tcltk.wxs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<Package InstallerVersion="500" Compressed="yes" InstallScope="perUser" />
55
<MediaTemplate EmbedCab="yes" CompressionLevel="high" />
66

7+
<PropertyRef Id="DetectTargetDir" />
78
<PropertyRef Id="UpgradeTable" />
89
<PropertyRef Id="REGISTRYKEY" />
910

Tools/msi/test/test.wxs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<Package InstallerVersion="500" Compressed="yes" InstallScope="perUser" />
55
<MediaTemplate EmbedCab="yes" CompressionLevel="high" />
66

7+
<PropertyRef Id="DetectTargetDir" />
78
<PropertyRef Id="UpgradeTable" />
89
<PropertyRef Id="REGISTRYKEY" />
910

Tools/msi/tools/tools.wxs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<Package InstallerVersion="500" Compressed="yes" InstallScope="perUser" />
55
<MediaTemplate EmbedCab="yes" CompressionLevel="high" />
66

7+
<PropertyRef Id="DetectTargetDir" />
78
<PropertyRef Id="UpgradeTable" />
89

910
<Feature Id="DefaultFeature" AllowAdvertise="no" Title="!(loc.Title)" Description="!(loc.Description)">

Tools/msi/ucrt/ucrt.wxs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<Package InstallerVersion="500" Compressed="yes" InstallScope="perUser" />
55
<MediaTemplate EmbedCab="yes" CompressionLevel="high" />
66

7+
<PropertyRef Id="DetectTargetDir" />
78
<PropertyRef Id="UpgradeTable" />
89
<PropertyRef Id="REGISTRYKEY" />
910

0 commit comments

Comments
 (0)
0