Skip to content

Commit

Permalink
Pull in main
Browse files Browse the repository at this point in the history
  • Loading branch information
erlend-aasland committed Apr 14, 2024
2 parents 090cc5d + c99d374 commit d8e8cc5
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 19 deletions.
14 changes: 11 additions & 3 deletions Doc/library/dataclasses.rst
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ Module contents

To create a shallow copy, the following workaround may be used::

dict((field.name, getattr(obj, field.name)) for field in fields(obj))
{field.name: getattr(obj, field.name) for field in fields(obj)}

:func:`!asdict` raises :exc:`TypeError` if *obj* is not a dataclass
instance.
Expand Down Expand Up @@ -430,8 +430,8 @@ Module contents

Creates a new object of the same type as *obj*, replacing
fields with values from *changes*. If *obj* is not a Data
Class, raises :exc:`TypeError`. If values in *changes* do not
specify fields, raises :exc:`TypeError`.
Class, raises :exc:`TypeError`. If keys in *changes* are not
field names of the given dataclass, raises :exc:`TypeError`.

The newly returned object is created by calling the :meth:`~object.__init__`
method of the dataclass. This ensures that
Expand Down Expand Up @@ -556,6 +556,8 @@ See the section below on init-only variables for ways to pass
parameters to :meth:`!__post_init__`. Also see the warning about how
:func:`replace` handles ``init=False`` fields.

.. _dataclasses-class-variables:

Class variables
---------------

Expand All @@ -567,6 +569,8 @@ from consideration as a field and is ignored by the dataclass
mechanisms. Such ``ClassVar`` pseudo-fields are not returned by the
module-level :func:`fields` function.

.. _dataclasses-init-only-variables:

Init-only variables
-------------------

Expand Down Expand Up @@ -598,6 +602,8 @@ value is not provided when creating the class::
In this case, :func:`fields` will return :class:`Field` objects for :attr:`!i` and
:attr:`!j`, but not for :attr:`!database`.

.. _dataclasses-frozen:

Frozen instances
----------------

Expand All @@ -611,6 +617,8 @@ There is a tiny performance penalty when using ``frozen=True``:
:meth:`~object.__init__` cannot use simple assignment to initialize fields, and
must use :meth:`!__setattr__`.

.. _dataclasses-inheritance:

Inheritance
-----------

Expand Down
9 changes: 5 additions & 4 deletions Doc/library/pathlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1004,10 +1004,6 @@ call fails (for example because the path doesn't exist).
.. seealso::
:ref:`pathlib-pattern-language` documentation.

This method calls :meth:`Path.is_dir` on the top-level directory and
propagates any :exc:`OSError` exception that is raised. Subsequent
:exc:`OSError` exceptions from scanning directories are suppressed.

By default, or when the *case_sensitive* keyword-only argument is set to
``None``, this method matches paths using platform-specific casing rules:
typically, case-sensitive on POSIX, and case-insensitive on Windows.
Expand All @@ -1028,6 +1024,11 @@ call fails (for example because the path doesn't exist).
.. versionchanged:: 3.13
The *pattern* parameter accepts a :term:`path-like object`.

.. versionchanged:: 3.13
Any :exc:`OSError` exceptions raised from scanning the filesystem are
suppressed. In previous versions, such exceptions are suppressed in many
cases, but not all.


.. method:: Path.rglob(pattern, *, case_sensitive=None, recurse_symlinks=False)

Expand Down
4 changes: 1 addition & 3 deletions Lib/pathlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,11 +607,9 @@ def glob(self, pattern, *, case_sensitive=None, recurse_symlinks=False):
if raw[-1] in (self.parser.sep, self.parser.altsep):
# GH-65238: pathlib doesn't preserve trailing slash. Add it back.
parts.append('')
if not self.is_dir():
return iter([])
select = self._glob_selector(parts[::-1], case_sensitive, recurse_symlinks)
root = str(self)
paths = select(root, exists=True)
paths = select(root)

# Normalize results
if root == '.':
Expand Down
4 changes: 1 addition & 3 deletions Lib/pathlib/_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,10 +705,8 @@ def glob(self, pattern, *, case_sensitive=None, recurse_symlinks=True):
anchor, parts = pattern._stack
if anchor:
raise NotImplementedError("Non-relative patterns are unsupported")
if not self.is_dir():
return iter([])
select = self._glob_selector(parts, case_sensitive, recurse_symlinks)
return select(self, exists=True)
return select(self)

def rglob(self, pattern, *, case_sensitive=None, recurse_symlinks=True):
"""Recursively yield all existing files (of any kind, including
Expand Down
7 changes: 7 additions & 0 deletions Lib/test/test_pathlib/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,13 @@ def test_glob_dot(self):
self.assertEqual(
set(P('.').glob('**/*/*')), {P("dirD/fileD")})

def test_glob_inaccessible(self):
P = self.cls
p = P(self.base, "mydir1", "mydir2")
p.mkdir(parents=True)
p.parent.chmod(0)
self.assertEqual(set(p.glob('*')), set())

def test_rglob_pathlike(self):
P = self.cls
p = P(self.base, "dirC")
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_pathlib/test_pathlib_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pathlib._abc import UnsupportedOperation, ParserBase, PurePathBase, PathBase
import posixpath

from test.support import is_wasi
from test.support.os_helper import TESTFN


Expand Down Expand Up @@ -1920,6 +1921,8 @@ def test_rglob_symlink_loop(self):
}
self.assertEqual(given, {p / x for x in expect})

# See https://github.com/WebAssembly/wasi-filesystem/issues/26
@unittest.skipIf(is_wasi, "WASI resolution of '..' parts doesn't match POSIX")
def test_glob_dotdot(self):
# ".." is not special in globs.
P = self.cls
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Speed up :meth:`pathlib.Path.glob` by omitting an initial
:meth:`~pathlib.Path.is_dir` call. As a result of this change,
:meth:`~pathlib.Path.glob` can no longer raise :exc:`OSError`.
8 changes: 4 additions & 4 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ EOF
if $CPP $CPPFLAGS conftest.c >conftest.out 2>/dev/null; then
ac_cv_cc_name=`grep -v '^#' conftest.out | grep -v '^ *$' | tr -d ' '`
if $(expr "//$CC" : '.*/\(.*\)') = "mpicc"; then
if test $(expr "//$CC" : '.*/\(.*\)') = "mpicc"; then
ac_cv_cc_name="mpicc"
fi
else
Expand Down Expand Up @@ -1131,10 +1131,10 @@ AC_MSG_CHECKING([for PEP 11 support tier])
AS_CASE([$host/$ac_cv_cc_name],
[x86_64-*-linux-gnu/gcc], [PY_SUPPORT_TIER=1], dnl Linux on AMD64, any vendor, glibc, gcc
[x86_64-apple-darwin*/clang], [PY_SUPPORT_TIER=1], dnl macOS on Intel, any version
[aarch64-apple-darwin*/clang], [PY_SUPPORT_TIER=1], dnl macOS on M1, any version
[i686-pc-windows-msvc/msvc], [PY_SUPPORT_TIER=1], dnl 32bit Windows on Intel, MSVC
[x86_64-pc-windows-msvc/msvc], [PY_SUPPORT_TIER=1], dnl 64bit Windows on AMD64, MSVC

[aarch64-apple-darwin*/clang], [PY_SUPPORT_TIER=2], dnl macOS on M1, any version
[aarch64-*-linux-gnu/gcc], [PY_SUPPORT_TIER=2], dnl Linux ARM64, glibc, gcc+clang
[aarch64-*-linux-gnu/clang], [PY_SUPPORT_TIER=2],
[powerpc64le-*-linux-gnu/gcc], [PY_SUPPORT_TIER=2], dnl Linux on PPC64 little endian, glibc, gcc
Expand Down

0 comments on commit d8e8cc5

Please sign in to comment.