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

Skip to content

Commit 7d4f3fd

Browse files
committed
Merge remote-tracking branch 'upstream/main' into pep696v2
2 parents 2c04c14 + 23950be commit 7d4f3fd

File tree

20 files changed

+538
-248
lines changed

20 files changed

+538
-248
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ jobs:
137137
uses: actions/cache@v4
138138
with:
139139
path: config.cache
140+
# Include env.pythonLocation in key to avoid changes in environment when setup-python updates Python
140141
key: ${{ github.job }}-${{ runner.os }}-${{ env.IMAGE_VERSION }}-${{ needs.check_source.outputs.config_hash }}-${{ env.pythonLocation }}
141142
- name: Install Dependencies
142143
run: sudo ./.github/workflows/posix-deps-apt.sh

.github/workflows/reusable-wasi.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ jobs:
5050
uses: actions/cache@v4
5151
with:
5252
path: ${{ env.CROSS_BUILD_PYTHON }}/config.cache
53-
key: ${{ github.job }}-${{ runner.os }}-${{ env.IMAGE_VERSION }}-${{ inputs.config_hash }}
53+
# Include env.pythonLocation in key to avoid changes in environment when setup-python updates Python
54+
key: ${{ github.job }}-${{ runner.os }}-${{ env.IMAGE_VERSION }}-${{ inputs.config_hash }}-${{ env.pythonLocation 10000 }}
5455
- name: "Configure build Python"
5556
run: python3 Tools/wasm/wasi.py configure-build-python -- --config-cache --with-pydebug
5657
- name: "Make build Python"
@@ -59,7 +60,8 @@ jobs:
5960
uses: actions/cache@v4
6061
with:
6162
path: ${{ env.CROSS_BUILD_WASI }}/config.cache
62-
key: ${{ github.job }}-${{ runner.os }}-${{ env.IMAGE_VERSION }}-wasi-sdk-${{ env.WASI_SDK_VERSION }}-${{ inputs.config_hash }}
63+
# Include env.pythonLocation in key to avoid changes in environment when setup-python updates Python
64+
key: ${{ github.job }}-${{ runner.os }}-${{ env.IMAGE_VERSION }}-wasi-sdk-${{ env.WASI_SDK_VERSION }}-${{ inputs.config_hash }}-${{ env.pythonLocation }}
6365
- name: "Configure host"
6466
# `--with-pydebug` inferred from configure-build-python
6567
run: python3 Tools/wasm/wasi.py configure-host -- --config-cache

Grammar/python.gram

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,10 +1303,14 @@ invalid_group:
13031303
invalid_import:
13041304
| a='import' ','.dotted_name+ 'from' dotted_name {
13051305
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "Did you mean to use 'from ... import ...' instead?") }
1306+
| 'import' token=NEWLINE {
1307+
RAISE_SYNTAX_ERROR_STARTING_FROM(token, "Expected one or more names after 'import'") }
13061308

13071309
invalid_import_from_targets:
13081310
| import_from_as_names ',' NEWLINE {
13091311
RAISE_SYNTAX_ERROR("trailing comma not allowed without surrounding parentheses") }
1312+
| token=NEWLINE {
1313+
RAISE_SYNTAX_ERROR_STARTING_FROM(token, "Expected one or more names after 'import'") }
13101314

13111315
invalid_compound_stmt:
13121316
| a='elif' named_expression ':' { RAISE_SYNTAX_ERROR_STARTING_FROM(a, "'elif' must match an if-statement here") }

Include/internal/pycore_import.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ extern int _PyImport_SetModuleString(const char *name, PyObject* module);
2222
extern void _PyImport_AcquireLock(PyInterpreterState *interp);
2323
extern int _PyImport_ReleaseLock(PyInterpreterState *interp);
2424

25+
// This is used exclusively for the sys and builtins modules:
2526
extern int _PyImport_FixupBuiltin(
2627
PyObject *mod,
2728
const char *name, /* UTF-8 encoded string */

Lib/test/test_capi/test_getargs.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -856,20 +856,24 @@ def test_y_hash(self):
856856

857857
def test_w_star(self):
858858
# getargs_w_star() modifies first and last byte
859-
from _testcapi import getargs_w_star
860-
self.assertRaises(TypeError, getargs_w_star, 'abc\xe9')
861-
self.assertRaises(TypeError, getargs_w_star, b'bytes')
862-
self.assertRaises(TypeError, getargs_w_star, b'nul:\0')
863-
self.assertRaises(TypeError, getargs_w_star, memoryview(b'bytes'))
864-
buf = bytearray(b'bytearray')
865-
self.assertEqual(getargs_w_star(buf), b'[ytearra]')
866-
self.assertEqual(buf, bytearray(b'[ytearra]'))
867-
buf = bytearray(b'memoryview')
868-
self.assertEqual(getargs_w_star(memoryview(buf)), b'[emoryvie]')
869-
self.assertEqual(buf, bytearray(b'[emoryvie]'))
870-
self.assertRaises(TypeError, getargs_w_star, None)
871-
self.assertRaises(TypeError, getargs_w_star< 8000 /span>, NONCONTIG_WRITABLE)
872-
self.assertRaises(TypeError, getargs_w_star, NONCONTIG_READONLY)
859+
# getargs_w_star_opt() takes additional optional args: with one
860+
# argument it should behave the same as getargs_w_star
861+
from _testcapi import getargs_w_star, getargs_w_star_opt
862+
for func in (getargs_w_star, getargs_w_star_opt):
863+
with self.subTest(func=func):
864+
self.assertRaises(TypeError, func, 'abc\xe9')
865+
self.assertRaises(TypeError, func, b'bytes')
866+
self.assertRaises(TypeError, func, b'nul:\0')
867+
self.assertRaises(TypeError, func, memoryview(b'bytes'))
868+
buf = bytearray(b'bytearray')
869+
self.assertEqual(func(buf), b'[ytearra]')
870+
self.assertEqual(buf, bytearray(b'[ytearra]'))
871+
buf = bytearray(b'memoryview')
872+
self.assertEqual(func(memoryview(buf)), b'[emoryvie]')
873+
self.assertEqual(buf, bytearray(b'[emoryvie]'))
874+
self.assertRaises(TypeError, func, None)
875+
self.assertRaises(TypeError, func, NONCONTIG_WRITABLE)
876+
self.assertRaises(TypeError, func, NONCONTIG_READONLY)
873877

874878
def test_getargs_empty(self):
875879
from _testcapi import getargs_empty
@@ -1112,9 +1116,9 @@ def test_skipitem(self):
11121116
c = chr(i)
11131117

11141118
# skip parentheses, the error reporting is inconsistent about them
1115-
# skip 'e', it's always a two-character code
1119+
# skip 'e' and 'w', they're always two-character codes
11161120
# skip '|' and '$', they don't represent arguments anyway
1117-
if c in '()e|$':
1121+
if c in '()ew|$':
11181122
continue
11191123

11201124
# test the format unit when not skipped
@@ -1152,7 +1156,7 @@ def test_skipitem_with_suffix(self):
11521156
dict_b = {'b':1}
11531157
keywords = ["a", "b"]
11541158

1155-
supported = ('s#', 's*', 'z#', 'z*', 'y#', 'y*', 'w#', 'w*')
1159+
supported = ('s#', 's*', 'z#', 'z*', 'y#', 'y*', 'w*')
11561160
for c in string.ascii_letters:
11571161
for c2 in '#*':
11581162
f = c + c2

Lib/test/test_concurrent_futures/test_init.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import time
55
import unittest
66
import sys
7+
import io
78
from concurrent.futures._base import BrokenExecutor
89
from concurrent.futures.process import _check_system_limits
910

@@ -124,7 +125,7 @@ def _test(self, test_class):
124125
except NotImplementedError:
125126
self.skipTest("ProcessPoolExecutor unavailable on this system")
126127

127-
runner = unittest.TextTestRunner()
128+
runner = unittest.TextTestRunner(stream=io.StringIO())
128129
runner.run(test_class('test_initializer'))
129130

130131
# GH-104090:

Lib/test/test_syntax.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,18 @@
16991699
Traceback (most recent call last):
17001700
SyntaxError: invalid syntax
17011701
1702+
>>> from i import
1703+
Traceback (most recent call last):
1704+
SyntaxError: Expected one or more names after 'import'
1705+
1706+
>>> from .. import
1707+
Traceback (most recent call last):
1708+
SyntaxError: Expected one or more names after 'import'
1709+
1710+
>>> import
1711+
Traceback (most recent call last):
1712+
SyntaxError: Expected one or more names after 'import'
1713+
17021714
>>> (): int
17031715
Traceback (most recent call last):
17041716
SyntaxError: only single target (not tuple) can be annotated

Lib/test/test_typing.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,38 @@ def foo(**kwargs: Unpack[Movie]): ...
11221122
self.assertEqual(repr(foo.__annotations__['kwargs']),
11231123
f"typing.Unpack[{__name__}.Movie]")
11241124

1125+
def test_builtin_tuple(self):
1126+
Ts = TypeVarTuple("Ts")
1127+
1128+
class Old(Generic[*Ts]): ...
1129+
class New[*Ts]: ...
1130+
1131+
PartOld = Old[int, *Ts]
1132+
self.assertEqual(PartOld[str].__args__, (int, str))
1133+
self.assertEqual(PartOld[*tuple[str]].__args__, (int, str))
1134+
self.assertEqual(PartOld[*Tuple[str]].__args__, (int, str))
1135+
self.assertEqual(PartOld[Unpack[tuple[str]]].__args__, (int, str))
1136+
self.assertEqual(PartOld[Unpack[Tuple[str]]].__args__, (int, str))
1137+
1138+
PartNew = New[int, *Ts]
1139+
self.assertEqual(PartNew[str].__args__, (int, str))
1140+
self.assertEqual(PartNew[*tuple[str]].__args__, (int, str))
1141+
self.assertEqual(PartNew[*Tuple[str]].__args__, (int, str))
1142+
self.assertEqual(PartNew[Unpack[tuple[str]]].__args__, (int, str))
1143+
self.assertEqual(PartNew[Unpack[Tuple[str]]].__args__, (int, str))
1144+
1145+
def test_unpack_wrong_type(self):
1146+
Ts = TypeVarTuple("Ts")
1147+
class Gen[*Ts]: ...
1148+
PartGen = Gen[int, *Ts]
1149+
1150+
bad_unpack_param = re.escape("Unpack[...] must be used with a tuple type")
1151+
with self.assertRaisesRegex(TypeError, bad_unpack_param):
1152+
PartGen[Unpack[list[int]]]
1153+
with self.assertRaisesRegex(TypeError, bad_unpack_param):
1154+
PartGen[Unpack[List[int]]]
1155+
1156+
11251157
class TypeVarTupleTests(BaseTestCase):
11261158

11271159
def assertEndsWith(self, string, tail):

Lib/typing.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,8 +1828,9 @@ def __typing_unpacked_tuple_args__(self):
18281828
assert self.__origin__ is Unpack
18291829
assert len(self.__args__) == 1
18301830
arg, = self.__args__
1831-
if isinstance(arg, _GenericAlias):
1832-
assert arg.__origin__ is tuple, arg.__origin__
1831+
if isinstance(arg, (_GenericAlias, types.GenericAlias)):
1832+
if arg.__origin__ is not tuple:
1833+
raise TypeError("Unpack[...] must be used with a tuple type")
18331834
return arg.__args__
18341835
return None
18351836

Makefile.pre.in

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ LIBHACL_SHA2_A= Modules/_hacl/libHacl_Hash_SHA2.a
233233
# Default zoneinfo.TZPATH. Added here to expose it in sysconfig.get_config_var
234234
TZPATH=@TZPATH@
235235

236+
# If to install mimalloc headers
237+
INSTALL_MIMALLOC=@INSTALL_MIMALLOC@
238+
236239
# Modes for directories, executables and data files created by the
237240
# install process. Default to user-only-writable for all file types.
238241
DIRMODE= 755
@@ -2616,6 +2619,12 @@ inclinstall:
26162619
$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$(INCLUDEPY)/internal; \
26172620
else true; \
26182621
fi
2622+
@if test "$(INSTALL_MIMALLOC)" == "yes"; then \
2623+
if test ! -d $(DESTDIR)$(INCLUDEPY)/internal/mimalloc/mimalloc; then \
2624+
echo "Creating directory $(DESTDIR)$(INCLUDEPY)/internal/mimalloc/mimalloc"; \
2625+
$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$(INCLUDEPY)/internal/mimalloc/mimalloc; \
2626+
fi; \
2627+
fi
26192628
@for i in $(srcdir)/Include/*.h; \
26202629
do \
26212630
echo $(INSTALL_DATA) $$i $(INCLUDEPY); \
@@ -2631,6 +2640,16 @@ inclinstall:
26312640
echo $(INSTALL_DATA) $$i $(INCLUDEPY)/internal; \
26322641
$(INSTALL_DATA) $$i $(DESTDIR)$(INCLUDEPY)/internal; \
26332642
done
2643+
@if test "$(INSTALL_MIMALLOC)" == "yes"; then \
2644+
echo $(INSTALL_DATA) $(srcdir)/Include/internal/mimalloc/mimalloc.h $(DESTDIR)$(INCLUDEPY)/internal/mimalloc/mimalloc.h; \
2645+
$(INSTALL_DATA) $(srcdir)/Include/internal/mimalloc/mimalloc.h $(DESTDIR)$(INCLUDEPY)/internal/mimalloc/mimalloc.h; \
2646+
for i in $(srcdir)/Include/internal/mimalloc/mimalloc/*.h; \
2647+
do \
2648+
echo $(INSTALL_DATA) $$i $(INCLUDEPY)/internal/mimalloc/mimalloc; \
2649+
$(INSTALL_DATA) $$i $(DESTDIR)$(INCLUDEPY)/internal/mimalloc/mimalloc; \
2650+
done; \
2651+
fi
2652+
echo $(INSTALL_DATA) pyconfig.h $(DESTDIR)$(CONFINCLUDEPY)/pyconfig.h
26342653
$(INSTALL_DATA) pyconfig.h $(DESTDIR)$(CONFINCLUDEPY)/pyconfig.h
26352654

26362655
# Install the library and miscellaneous stuff needed for extending/embedding

0 commit comments

Comments
 (0)
0