Skip to content

Commit fea5b34

Browse files
Merge branch 'main' into enc-normalize-speedup
2 parents 4912719 + 12805ef commit fea5b34

File tree

20 files changed

+310
-145
lines changed

20 files changed

+310
-145
lines changed

.github/CODEOWNERS

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,10 @@ Lib/test/test_getpath.py @FFY00
241241
Modules/getpath* @FFY00
242242

243243
# Hashing / ``hash()`` and related
244-
Include/cpython/pyhash.h @gpshead @picnixz @tiran
245-
Include/internal/pycore_pyhash.h @gpshead @picnixz @tiran
246-
Include/pyhash.h @gpshead @picnixz @tiran
247-
Python/pyhash.c @gpshead @picnixz @tiran
244+
Include/cpython/pyhash.h @gpshead @picnixz
245+
Include/internal/pycore_pyhash.h @gpshead @picnixz
246+
Include/pyhash.h @gpshead @picnixz
247+
Python/pyhash.c @gpshead @picnixz
248248

249249
# The import system (including importlib)
250250
**/*import* @brettcannon @ericsnowcurrently @ncoghlan @warsaw
@@ -371,14 +371,14 @@ Lib/calendar.py @AA-Turner
371371
Lib/test/test_calendar.py @AA-Turner
372372

373373
# Cryptographic Primitives and Applications
374-
**/*hashlib* @gpshead @picnixz @tiran
375-
**/*hashopenssl* @gpshead @picnixz @tiran
374+
**/*hashlib* @gpshead @picnixz
375+
**/*hashopenssl* @gpshead @picnixz
376376
**/*hmac* @gpshead @picnixz
377377
**/*ssl* @gpshead @picnixz
378378
Modules/_hacl/ @gpshead @picnixz
379-
Modules/*blake* @gpshead @picnixz @tiran
380-
Modules/*md5* @gpshead @picnixz @tiran
381-
Modules/*sha* @gpshead @picnixz @tiran
379+
Modules/*blake* @gpshead @picnixz
380+
Modules/*md5* @gpshead @picnixz
381+
Modules/*sha* @gpshead @picnixz
382382

383383
# Codecs
384384
Modules/cjkcodecs/ @corona10

Doc/library/hashlib.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ a file or file-like object.
310310
.. versionadded:: 3.11
311311

312312
.. versionchanged:: 3.14
313-
Now raises a :exc:`BlockingIOError` if the file is opened in blocking
313+
Now raises a :exc:`BlockingIOError` if the file is opened in non-blocking
314314
mode. Previously, spurious null bytes were added to the digest.
315315

316316

Include/internal/pycore_interp_structs.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -672,11 +672,6 @@ struct _Py_interp_cached_objects {
672672

673673
/* object.__reduce__ */
674674
PyObject *objreduce;
675-
#ifndef Py_GIL_DISABLED
676-
/* resolve_slotdups() */
677-
PyObject *type_slots_pname;
678-
pytype_slotdef *type_slots_ptrs[MAX_EQUIV];
679-
#endif
680675

681676
/* TypeVar and related types */
682677
PyTypeObject *generic_type;

Include/internal/pycore_typeobject.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ typedef int (*_py_validate_type)(PyTypeObject *);
152152
extern int _PyType_Validate(PyTypeObject *ty, _py_validate_type validate, unsigned int *tp_version);
153153
extern int _PyType_CacheGetItemForSpecialization(PyHeapTypeObject *ht, PyObject *descriptor, uint32_t tp_version);
154154

155+
// Precalculates count of non-unique slots and fills wrapperbase.name_count.
156+
extern int _PyType_InitSlotDefs(PyInterpreterState *interp);
157+
155158
#ifdef __cplusplus
156159
}
157160
#endif

Lib/test/test_asyncio/test_eager_task_factory.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,9 @@ def tearDown(self):
316316
asyncio.all_tasks = asyncio.tasks.all_tasks = self._all_tasks
317317
return super().tearDown()
318318

319-
320-
@unittest.skip("skip")
321319
def test_issue105987(self):
322320
code = """if 1:
323-
from _asyncio import _swap_current_task
321+
from _asyncio import _swap_current_task, _set_running_loop
324322
325323
class DummyTask:
326324
pass
@@ -329,6 +327,7 @@ class DummyLoop:
329327
pass
330328
331329
l = DummyLoop()
330+
_set_running_loop(l)
332331
_swap_current_task(l, DummyTask())
333332
t = _swap_current_task(l, None)
334333
"""

Lib/test/test_os/test_os.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3197,13 +3197,16 @@ def test_spawnvpe_invalid_env(self):
31973197
self._test_invalid_env(os.spawnvpe)
31983198

31993199

3200-
# The introduction of this TestCase caused at least two different errors on
3201-
# *nix buildbots. Temporarily skip this to let the buildbots move along.
3202-
@unittest.skip("Skip due to platform/environment differences on *NIX buildbots")
32033200
@unittest.skipUnless(hasattr(os, 'getlogin'), "test needs os.getlogin")
32043201
class LoginTests(unittest.TestCase):
32053202
def test_getlogin(self):
3206-
user_name = os.getlogin()
3203+
try:
3204+
user_name = os.getlogin()
3205+
except OSError as exc:
3206+
if exc.errno in (errno.ENOTTY, errno.ENXIO):
3207+
self.skipTest(str(exc))
3208+
else:
3209+
raise
32073210
self.assertNotEqual(len(user_name), 0)
32083211

32093212

@@ -4080,6 +4083,7 @@ def test_oserror_filename(self):
40804083
(self.filenames, os.listdir,),
40814084
(self.filenames, os.rename, "dst"),
40824085
(self.filenames, os.replace, "dst"),
4086+
(self.filenames, os.utime, None),
40834087
]
40844088
if os_helper.can_chmod():
40854089
funcs.append((self.filenames, os.chmod, 0o777))
@@ -4120,6 +4124,19 @@ def test_oserror_filename(self):
41204124
else:
41214125
self.fail(f"No exception thrown by {func}")
41224126

4127+
def test_mkdir(self):
4128+
filename = os_helper.TESTFN
4129+
subdir = os.path.join(filename, 'subdir')
4130+
self.assertRaises(FileNotFoundError, os.mkdir, subdir)
4131+
4132+
self.addCleanup(os_helper.unlink, filename)
4133+
create_file(filename)
4134+
self.assertRaises(FileExistsError, os.mkdir, filename)
4135+
4136+
self.assertRaises((NotADirectoryError, FileNotFoundError),
4137+
os.mkdir, subdir)
4138+
4139+
41234140
class CPUCountTests(unittest.TestCase):
41244141
def check_cpu_count(self, cpus):
41254142
if cpus is None:

Lib/test/test_os/test_windows.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,41 +21,6 @@
2121
from .utils import create_file
2222

2323

24-
class Win32ErrorTests(unittest.TestCase):
25-
def setUp(self):
26-
try:
27-
os.stat(os_helper.TESTFN)
28-
except FileNotFoundError:
29-
exists = False
30-
except OSError as exc:
31-
exists = True
32-
self.fail("file %s must not exist; os.stat failed with %s"
33-
% (os_helper.TESTFN, exc))
34-
else:
35-
self.fail("file %s must not exist" % os_helper.TESTFN)
36-
37-
def test_rename(self):
38-
self.assertRaises(OSError, os.rename, os_helper.TESTFN, os_helper.TESTFN+".bak")
39-
40-
def test_remove(self):
41-
self.assertRaises(OSError, os.remove, os_helper.TESTFN)
42-
43-
def test_chdir(self):
44-
self.assertRaises(OSError, os.chdir, os_helper.TESTFN)
45-
46-
def test_mkdir(self):
47-
self.addCleanup(os_helper.unlink, os_helper.TESTFN)
48-
49-
with open(os_helper.TESTFN, "x") as f:
50-
self.assertRaises(OSError, os.mkdir, os_helper.TESTFN)
51-
52-
def test_utime(self):
53-
self.assertRaises(OSError, os.utime, os_helper.TESTFN, None)
54-
55-
def test_chmod(self):
56-
self.assertRaises(OSError, os.chmod, os_helper.TESTFN, 0)
57-
58-
5924
class Win32KillTests(unittest.TestCase):
6025
def _kill(self, sig):
6126
# Start sys.executable as a subprocess and communicate from the

Lib/test/test_ssl.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4346,8 +4346,14 @@ def test_client_sigalgs_mismatch(self):
43464346
client_context.set_client_sigalgs("rsa_pss_rsae_sha256")
43474347
server_context.set_client_sigalgs("rsa_pss_rsae_sha384")
43484348

4349-
# Some systems return ConnectionResetError on handshake failures
4350-
with self.assertRaises((ssl.SSLError, ConnectionResetError)):
4349+
with self.assertRaises((
4350+
ssl.SSLError,
4351+
# On handshake failures, some systems raise a ConnectionResetError.
4352+
ConnectionResetError,
4353+
# On handshake failures, macOS may raise a BrokenPipeError.
4354+
# See https://github.com/python/cpython/issues/139504.
4355+
BrokenPipeError,
4356+
)):
43514357
server_params_test(client_context, server_context,
43524358
chatty=True, connectionchatty=True,
43534359
sni_name=hostname)

Lib/test/test_support.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,13 @@ def test_get_attribute(self):
9696
self.test_get_attribute)
9797
self.assertRaises(unittest.SkipTest, support.get_attribute, self, "foo")
9898

99-
@unittest.skip("failing buildbots")
10099
def test_get_original_stdout(self):
101-
self.assertEqual(support.get_original_stdout(), sys.stdout)
100+
if isinstance(sys.stdout, io.StringIO):
101+
# gh-55258: When --junit-xml is used, stdout is a StringIO:
102+
# use sys.__stdout__ in this case.
103+
self.assertEqual(support.get_original_stdout(), sys.__stdout__)
104+
else:
105+
self.assertEqual(support.get_original_stdout(), sys.stdout)
102106

103107
def test_unload(self):
104108
import sched # noqa: F401

Lib/test/test_typing.py

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from typing import dataclass_transform
3636
from typing import no_type_check, no_type_check_decorator
3737
from typing import Type
38-
from typing import NamedTuple, NotRequired, Required, ReadOnly, TypedDict
38+
from typing import NamedTuple, NotRequired, Required, ReadOnly, TypedDict, NoExtraItems
3939
from typing import IO, TextIO, BinaryIO
4040
from typing import Pattern, Match
4141
from typing import Annotated, ForwardRef
@@ -8820,6 +8820,32 @@ class ChildWithInlineAndOptional(Untotal, Inline):
88208820
class Wrong(*bases):
88218821
pass
88228822

8823+
def test_closed_values(self):
8824+
class Implicit(TypedDict): ...
8825+
class ExplicitTrue(TypedDict, closed=True): ...
8826+
class ExplicitFalse(TypedDict, closed=False): ...
8827+
8828+
self.assertIsNone(Implicit.__closed__)
8829+
self.assertIs(ExplicitTrue.__closed__, True)
8830+
self.assertIs(ExplicitFalse.__closed__, False)
8831+
8832+
def test_extra_items_class_arg(self):
8833+
class TD(TypedDict, extra_items=int):
8834+
a: str
8835+
8836+
self.assertIs(TD.__extra_items__, int)
8837+
self.assertEqual(TD.__annotations__, {'a': str})
8838+
self.assertEqual(TD.__required_keys__, frozenset({'a'}))
8839+
self.assertEqual(TD.__optional_keys__, frozenset())
8840+
8841+
class NoExtra(TypedDict):
8842+
a: str
8843+
8844+
self.assertIs(NoExtra.__extra_items__, NoExtraItems)
8845+
self.assertEqual(NoExtra.__annotations__, {'a': str})
8846+
self.assertEqual(NoExtra.__required_keys__, frozenset({'a'}))
8847+
self.assertEqual(NoExtra.__optional_keys__, frozenset())
8848+
88238849
def test_is_typeddict(self):
88248850
self.assertIs(is_typeddict(Point2D), True)
88258851
self.assertIs(is_typeddict(Union[str, int]), False)
@@ -9147,6 +9173,71 @@ class AllTheThings(TypedDict):
91479173
},
91489174
)
91499175

9176+
def test_closed_inheritance(self):
9177+
class Base(TypedDict, extra_items=ReadOnly[Union[str, None]]):
9178+
a: int
9179+
9180+
self.assertEqual(Base.__required_keys__, frozenset({"a"}))
9181+
self.assertEqual(Base.__optional_keys__, frozenset({}))
9182+
self.assertEqual(Base.__readonly_keys__, frozenset({}))
9183+
self.assertEqual(Base.__mutable_keys__, frozenset({"a"}))
9184+
self.assertEqual(Base.__annotations__, {"a": int})
9185+
self.assertEqual(Base.__extra_items__, ReadOnly[Union[str, None]])
9186+
self.assertIsNone(Base.__closed__)
9187+
9188+
class Child(Base, extra_items=int):
9189+
a: str
9190+
9191+
self.assertEqual(Child.__required_keys__, frozenset({'a'}))
9192+
self.assertEqual(Child.__optional_keys__, frozenset({}))
9193+
self.assertEqual(Child.__readonly_keys__, frozenset({}))
9194+
self.assertEqual(Child.__mutable_keys__, frozenset({'a'}))
9195+
self.assertEqual(Child.__annotations__, {"a": str})
9196+
self.assertIs(Child.__extra_items__, int)
9197+
self.assertIsNone(Child.__closed__)
9198+
9199+
class GrandChild(Child, closed=True):
9200+
a: float
9201+
9202+
self.assertEqual(GrandChild.__required_keys__, frozenset({'a'}))
9203+
self.assertEqual(GrandChild.__optional_keys__, frozenset({}))
9204+
self.assertEqual(GrandChild.__readonly_keys__, frozenset({}))
9205+
self.assertEqual(GrandChild.__mutable_keys__, frozenset({'a'}))
9206+
self.assertEqual(GrandChild.__annotations__, {"a": float})
9207+
self.assertIs(GrandChild.__extra_items__, NoExtraItems)
9208+
self.assertIs(GrandChild.__closed__, True)
9209+
9210+
class GrandGrandChild(GrandChild):
9211+
...
9212+
self.assertEqual(GrandGrandChild.__required_keys__, frozenset({'a'}))
9213+
self.assertEqual(GrandGrandChild.__optional_keys__, frozenset({}))
9214+
self.assertEqual(GrandGrandChild.__readonly_keys__, frozenset({}))
9215+
self.assertEqual(GrandGrandChild.__mutable_keys__, frozenset({'a'}))
9216+
self.assertEqual(GrandGrandChild.__annotations__, {"a": float})
9217+
self.assertIs(GrandGrandChild.__extra_items__, NoExtraItems)
9218+
self.assertIsNone(GrandGrandChild.__closed__)
9219+
9220+
def test_implicit_extra_items(self):
9221+
class Base(TypedDict):
9222+
a: int
9223+
9224+
self.assertIs(Base.__extra_items__, NoExtraItems)
9225+
self.assertIsNone(Base.__closed__)
9226+
9227+
class ChildA(Base, closed=True):
9228+
...
9229+
9230+
self.assertEqual(ChildA.__extra_items__, NoExtraItems)
9231+
self.assertIs(ChildA.__closed__, True)
9232+
9233+
def test_cannot_combine_closed_and_extra_items(self):
9234+
with self.assertRaisesRegex(
9235+
TypeError,
9236+
"Cannot combine closed=True and extra_items"
9237+
):
9238+
class TD(TypedDict, closed=True, extra_items=range):
9239+
x: str
9240+
91509241
def test_annotations(self):
91519242
# _type_check is applied
91529243
with self.assertRaisesRegex(TypeError, "Plain typing.Final is not valid as type argument"):
@@ -9376,6 +9467,12 @@ class A(typing.Match):
93769467
class B(typing.Pattern):
93779468
pass
93789469

9470+
def test_typed_dict_signature(self):
9471+
self.assertListEqual(
9472+
list(inspect.signature(TypedDict).parameters),
9473+
['typename', 'fields', 'total', 'closed', 'extra_items']
9474+
)
9475+
93799476

93809477
class AnnotatedTests(BaseTestCase):
93819478

0 commit comments

Comments
 (0)