Skip to content

[pull] main from python:main #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 11, 2025
2 changes: 1 addition & 1 deletion Doc/library/typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2771,7 +2771,7 @@ types.

.. versionadded:: 3.13

See :pep:`589` for more examples and detailed rules of using ``TypedDict``.
See the `TypedDict <https://typing.python.org/en/latest/spec/typeddict.html#typeddict>`_ section in the typing documentation for more examples and detailed rules.

.. versionadded:: 3.8

Expand Down
4 changes: 2 additions & 2 deletions Lib/test/clinic.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -4940,7 +4940,7 @@ static int
Test_metho_not_default_return_converter_impl(TestObj *self, PyObject *a);

static PyObject *
Test_metho_not_default_return_converter(TestObj *self, PyObject *a)
Test_metho_not_default_return_converter(PyObject *self, PyObject *a)
{
PyObject *return_value = NULL;
int _return_value;
Expand All @@ -4957,7 +4957,7 @@ Test_metho_not_default_return_converter(TestObj *self, PyObject *a)

static int
Test_metho_not_default_return_converter_impl(TestObj *self, PyObject *a)
/*[clinic end generated code: output=b2cce75a7af2e6ce input=428657129b521177]*/
/*[clinic end generated code: output=8b03f5213c312138 input=428657129b521177]*/


/*[clinic input]
Expand Down
1 change: 1 addition & 0 deletions Lib/test/libregrtest/tsan.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# chosen because they use threads and run in a reasonable amount of time.

TSAN_TESTS = [
'test_asyncio.test_free_threading',
# TODO: enable more of test_capi once bugs are fixed (GH-116908, GH-116909).
'test_capi.test_mem',
'test_capi.test_pyatomic',
Expand Down
9 changes: 6 additions & 3 deletions Lib/test/test_asyncio/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2301,16 +2301,19 @@ class Subclass(Task):
def __del__(self):
pass

async def coro():
async def corofn():
await asyncio.sleep(0.01)

task = Subclass(coro(), loop = self.loop)
coro = corofn()
task = Subclass(coro, loop = self.loop)
task._log_destroy_pending = False

del task

support.gc_collect()

coro.close()

@mock.patch('asyncio.base_events.logger')
def test_tb_logger_not_called_after_cancel(self, m_log):
loop = asyncio.new_event_loop()
Expand Down Expand Up @@ -2716,12 +2719,12 @@ def __str__(self):
coro = coroutine_function()
with contextlib.closing(asyncio.EventLoop()) as loop:
task = asyncio.Task.__new__(asyncio.Task)

for _ in range(5):
with self.assertRaisesRegex(RuntimeError, 'break'):
task.__init__(coro, loop=loop, context=obj, name=Break())

coro.close()
task._log_destroy_pending = False
del task

self.assertEqual(sys.getrefcount(obj), initial_refcount)
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_pathlib/support/lexical_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Simple implementation of JoinablePath, for use in pathlib tests.
"""

import ntpath
import os.path
import pathlib.types
import posixpath
Expand Down Expand Up @@ -37,3 +38,8 @@ def with_segments(self, *pathsegments):
class LexicalPosixPath(LexicalPath):
__slots__ = ()
parser = posixpath


class LexicalWindowsPath(LexicalPath):
__slots__ = ()
parser = ntpath
145 changes: 145 additions & 0 deletions Lib/test/test_pathlib/support/local_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
"""
Implementation of ReadablePath for local paths, for use in pathlib tests.

LocalPathGround is also defined here. It helps establish the "ground truth"
about local paths in tests.
"""

import os
import pathlib.types

from test.support import os_helper
from test.test_pathlib.support.lexical_path import LexicalPath


class LocalPathGround:
can_symlink = os_helper.can_symlink()

def __init__(self, path_cls):
self.path_cls = path_cls

def setup(self, local_suffix=""):
root = self.path_cls(os_helper.TESTFN + local_suffix)
os.mkdir(root)
return root

def teardown(self, root):
os_helper.rmtree(root)

def create_file(self, p, data=b''):
with open(p, 'wb') as f:
f.write(data)

def create_dir(self, p):
os.mkdir(p)

def create_symlink(self, p, target):
os.symlink(target, p)

def create_hierarchy(self, p):
os.mkdir(os.path.join(p, 'dirA'))
os.mkdir(os.path.join(p, 'dirB'))
os.mkdir(os.path.join(p, 'dirC'))
os.mkdir(os.path.join(p, 'dirC', 'dirD'))
with open(os.path.join(p, 'fileA'), 'wb') as f:
f.write(b"this is file A\n")
with open(os.path.join(p, 'dirB', 'fileB'), 'wb') as f:
f.write(b"this is file B\n")
with open(os.path.join(p, 'dirC', 'fileC'), 'wb') as f:
f.write(b"this is file C\n")
with open(os.path.join(p, 'dirC', 'novel.txt'), 'wb') as f:
f.write(b"this is a novel\n")
with open(os.path.join(p, 'dirC', 'dirD', 'fileD'), 'wb') as f:
f.write(b"this is file D\n")
if self.can_symlink:
# Relative symlinks.
os.symlink('fileA', os.path.join(p, 'linkA'))
os.symlink('non-existing', os.path.join(p, 'brokenLink'))
os.symlink('dirB',
os.path.join(p, 'linkB'),
target_is_directory=True)
os.symlink(os.path.join('..', 'dirB'),
os.path.join(p, 'dirA', 'linkC'),
target_is_directory=True)
# Broken symlink (pointing to itself).
os.symlink('brokenLinkLoop', os.path.join(p, 'brokenLinkLoop'))

isdir = staticmethod(os.path.isdir)
isfile = staticmethod(os.path.isfile)
islink = staticmethod(os.path.islink)
readlink = staticmethod(os.readlink)

def readtext(self, p):
with open(p, 'r') as f:
return f.read()

def readbytes(self, p):
with open(p, 'rb') as f:
return f.read()


class LocalPathInfo(pathlib.types.PathInfo):
"""
Simple implementation of PathInfo for a local path
"""
__slots__ = ('_path', '_exists', '_is_dir', '_is_file', '_is_symlink')

def __init__(self, path):
self._path = str(path)
self._exists = None
self._is_dir = None
self._is_file = None
self._is_symlink = None

def exists(self, *, follow_symlinks=True):
"""Whether this path exists."""
if not follow_symlinks and self.is_symlink():
return True
if self._exists is None:
self._exists = os.path.exists(self._path)
return self._exists

def is_dir(self, *, follow_symlinks=True):
"""Whether this path is a directory."""
if not follow_symlinks and self.is_symlink():
return False
if self._is_dir is None:
self._is_dir = os.path.isdir(self._path)
return self._is_dir

def is_file(self, *, follow_symlinks=True):
"""Whether this path is a regular file."""
if not follow_symlinks and self.is_symlink():
return False
if self._is_file is None:
self._is_file = os.path.isfile(self._path)
return self._is_file

def is_symlink(self):
"""Whether this path is a symbolic link."""
if self._is_symlink is None:
self._is_symlink = os.path.islink(self._path)
return self._is_symlink


class ReadableLocalPath(pathlib.types._ReadablePath, LexicalPath):
"""
Simple implementation of a ReadablePath class for local filesystem paths.
"""
__slots__ = ('info',)

def __init__(self, *pathsegments):
super().__init__(*pathsegments)
self.info = LocalPathInfo(self)

def __fspath__(self):
return str(self)

def __open_rb__(self, buffering=-1):
return open(self, 'rb')

def iterdir(self):
return (self / name for name in os.listdir(self))

def readlink(self):
return self.with_segments(os.readlink(self))
Loading