From dab7fc6b1c26d656cfecbfccf6bedbc75dcdadba Mon Sep 17 00:00:00 2001 From: Andreas Poehlmann Date: Sun, 8 Nov 2026 20:00:58 +0100 Subject: [PATCH 1/2] Add support for Python 3.15 - ci: run tests and typesafety checks on python 3.15 - nox: add 3.15, drop the aiohttp/pydantic install workaround for 3.14 since binary wheels are available now - upath: accept the parent_mode keyword argument added to pathlib.Path.mkdir() in python 3.15, and backport it for local paths on older python versions - upath.implementations.local: keep is_reserved() on python 3.15+, where pathlib removed it, and emit the DeprecationWarning pathlib emitted on python 3.13 and 3.14 - docs: add python 3.15 to the compatibility table --- .github/workflows/tests.yml | 4 +- README.md | 186 +++++++++++----------- docs/concepts/pathlib.md | 2 +- docs/why.md | 2 +- noxfile.py | 9 +- pyproject.toml | 1 + upath/core.py | 8 + upath/extensions.py | 7 +- upath/implementations/cloud.py | 24 ++- upath/implementations/data.py | 7 +- upath/implementations/ftp.py | 4 +- upath/implementations/github.py | 2 + upath/implementations/hdfs.py | 11 +- upath/implementations/http.py | 2 + upath/implementations/local.py | 42 +++++ upath/implementations/smb.py | 2 + upath/implementations/tar.py | 2 + upath/implementations/zip.py | 2 + upath/tests/cases.py | 9 ++ upath/tests/implementations/test_local.py | 26 +++ 20 files changed, 239 insertions(+), 113 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 115a286e..41037f85 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -24,7 +24,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] - pyv: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14'] + pyv: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14', '3.15'] session: ['tests'] include: @@ -48,7 +48,7 @@ jobs: strategy: fail-fast: false matrix: - pyv: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14'] + pyv: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14', '3.15'] steps: - name: Check out the repository diff --git a/README.md b/README.md index f53b25a8..ba3c5757 100644 --- a/README.md +++ b/README.md @@ -283,99 +283,99 @@ matrix for stdlib pathlib.Path attributes and methods. Methods supported in UPath should correctly work for all supported Python versions. If not, we consider it a bug. -| Method/Attribute | py3.9 | py3.10 | py3.11 | py3.12 | py3.13 | py3.14 | UPath | -|---------------------------|-------|--------|--------|--------|--------|--------|-------| -| **Pure Paths** | | | | | | | | -| _Operators_ | | | | | | | | -| `__truediv__` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `__rtruediv__` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| _Access individual Parts_ | | | | | | | | -| `parts` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| _Methods and Properties_ | | | | | | | | -| `parser` | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | -| `drive` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `root` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `anchor` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `parents` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `parent` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `name` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `suffix` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `suffixes` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `stem` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `as_posix()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `is_absolute()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `is_relative_to()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `is_reserved()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `joinpath()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `full_match()` | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | -| `match()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `relative_to()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `with_name()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `with_stem()` | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `with_suffix()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `with_segments()` | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | -| **Concrete Paths** | | | | | | | | -| _Parsing URIs_ | | | | | | | | -| `from_uri()` | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | -| `as_uri()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| _Expanding Paths_ | | | | | | | | -| `home()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `expanduser()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `cwd()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `absolute()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `resolve()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `readlink()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ⚠️ | -| _Querying File status_ | | | | | | | | -| `stat()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `lstat()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `exists()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `is_file()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `is_dir()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `is_symlink()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `is_junction()` | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | -| `is_mount()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `is_socket()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `is_fifo()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `is_block_device()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `is_char_device()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `samefile()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `info` | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | -| _Reading & Writing Files_ | | | | | | | | -| `open()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `read_text()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `read_bytes()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `write_text()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `write_bytes()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| _Reading Directories_ | | | | | | | | -| `iterdir()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `glob()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `rglob()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `walk()` | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | -| _Creating Files & Dirs_ | | | | | | | | -| `touch()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `mkdir()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `symlink_to()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ⚠️ | -| `hardlink_to()` | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ⚠️ | -| _Copying & Moving_ | | | | | | | | -| `copy()` | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | -| `copy_into()` | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | -| `rename()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `replace()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ⚠️ | -| `move()` | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | -| `move_into()` | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | -| `unlink()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| `rmdir()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| _Permission & Owner_ | | | | | | | | -| `owner()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ⚠️ | -| `group()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ⚠️ | -| `chmod()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ⚠️ | -| `lchmod()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ⚠️ | -| **UPath interface** | | | | | | | | -| `protocol` | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | -| `storage_options` | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | -| `path` | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | -| `fs` | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | -| `joinuri()` | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | +| Method/Attribute | py3.9 | py3.10 | py3.11 | py3.12 | py3.13 | py3.14 | py3.15 | UPath | +|---------------------------|-------|--------|--------|--------|--------|--------|--------|-------| +| **Pure Paths** | | | | | | | | | +| _Operators_ | | | | | | | | | +| `__truediv__` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `__rtruediv__` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| _Access individual Parts_ | | | | | | | | | +| `parts` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| _Methods and Properties_ | | | | | | | | | +| `parser` | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | +| `drive` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `root` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `anchor` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `parents` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `parent` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `name` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `suffix` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `suffixes` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `stem` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `as_posix()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `is_absolute()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `is_relative_to()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `is_reserved()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | +| `joinpath()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `full_match()` | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | +| `match()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `relative_to()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `with_name()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `with_stem()` | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `with_suffix()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `with_segments()` | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | +| **Concrete Paths** | | | | | | | | | +| _Parsing URIs_ | | | | | | | | | +| `from_uri()` | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | +| `as_uri()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| _Expanding Paths_ | | | | | | | | | +| `home()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `expanduser()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `cwd()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `absolute()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `resolve()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `readlink()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ⚠️ | +| _Querying File status_ | | | | | | | | | +| `stat()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `lstat()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `exists()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `is_file()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `is_dir()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `is_symlink()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `is_junction()` | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `is_mount()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `is_socket()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `is_fifo()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `is_block_device()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `is_char_device()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `samefile()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `info` | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | +| _Reading & Writing Files_ | | | | | | | | | +| `open()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `read_text()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `read_bytes()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `write_text()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `write_bytes()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| _Reading Directories_ | | | | | | | | | +| `iterdir()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `glob()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `rglob()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `walk()` | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | +| _Creating Files & Dirs_ | | | | | | | | | +| `touch()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `mkdir()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `symlink_to()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ⚠️ | +| `hardlink_to()` | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ⚠️ | +| _Copying & Moving_ | | | | | | | | | +| `copy()` | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | +| `copy_into()` | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | +| `rename()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `replace()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ⚠️ | +| `move()` | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | +| `move_into()` | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | +| `unlink()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| `rmdir()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| _Permission & Owner_ | | | | | | | | | +| `owner()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ⚠️ | +| `group()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ⚠️ | +| `chmod()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ⚠️ | +| `lchmod()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ⚠️ | +| **UPath interface** | | | | | | | | | +| `protocol` | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | +| `storage_options` | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | +| `path` | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | +| `fs` | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | +| `joinuri()` | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | **Key:** - ✅ = Available/Supported diff --git a/docs/concepts/pathlib.md b/docs/concepts/pathlib.md index c2c0286f..fec866a6 100644 --- a/docs/concepts/pathlib.md +++ b/docs/concepts/pathlib.md @@ -82,7 +82,7 @@ pathlib-abc extracts the core concepts from Python's pathlib module into abstrac 4. **Ensure compatibility** between different path implementations !!! info "Relationship to Python's pathlib" - Currently (as of Python 3.14), the standard library `pathlib.Path` does **not** inherit from public pathlib-abc classes. However, there is ongoing work to incorporate these ABCs into future Python releases. + Currently (as of Python 3.15), the standard library `pathlib.Path` does **not** inherit from public pathlib-abc classes. However, there is ongoing work to incorporate these ABCs into future Python releases. The library defines three main abstract base classes that represent different levels of path functionality: diff --git a/docs/why.md b/docs/why.md index db4f8555..c9054dc2 100644 --- a/docs/why.md +++ b/docs/why.md @@ -200,7 +200,7 @@ s3_result = process_file(UPath("s3://bucket/file.txt")) Universal Pathlib runs a large subset of CPython's pathlib test suite: - :white_check_mark: **Compatibility tested** against standard library pathlib -- :white_check_mark: **Cross-version tested** on Python 3.9-3.14 +- :white_check_mark: **Cross-version tested** on Python 3.9-3.15 - :white_check_mark: **Integration tested** with real filesystems - :white_check_mark: **Regression tested** for each release diff --git a/noxfile.py b/noxfile.py index 044529cd..c0a013ea 100644 --- a/noxfile.py +++ b/noxfile.py @@ -16,7 +16,7 @@ locations = ("upath",) running_in_ci = os.environ.get("CI", "") != "" -SUPPORTED_PYTHONS = ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"] +SUPPORTED_PYTHONS = ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "3.15"] BASE_PYTHON = SUPPORTED_PYTHONS[-3] MIN_PYTHON = SUPPORTED_PYTHONS[0] @@ -52,12 +52,7 @@ def FSSPEC_MIN_VERSION() -> str: @nox.session(python=SUPPORTED_PYTHONS) def tests(session: nox.Session) -> None: """Run the test suite.""" - # workaround in case no aiohttp binary wheels are available - if session.python == "3.14": - session.env["AIOHTTP_NO_EXTENSIONS"] = "1" - session.install(".[tests,dev]", "pydantic>=2.12.0a1") - else: - session.install(".[tests,dev,dev-third-party]") + session.install(".[tests,dev,dev-third-party]") session.run("uv", "pip", "freeze", silent=not running_in_ci) session.run( "pytest", diff --git a/pyproject.toml b/pyproject.toml index aa9e96f0..b5bc159a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,6 +27,7 @@ classifiers = [ "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", "Programming Language :: Python :: 3.14", + "Programming Language :: Python :: 3.15", "Development Status :: 4 - Beta", ] keywords = ["filesystem-spec", "pathlib"] diff --git a/upath/core.py b/upath/core.py index 90ebac60..047a9574 100644 --- a/upath/core.py +++ b/upath/core.py @@ -1399,10 +1399,18 @@ def mkdir( mode: int = 0o777, parents: bool = False, exist_ok: bool = False, + *, + parent_mode: int | None = None, ) -> None: """ Create a new directory at this given path. """ + if parent_mode is not None: + warnings.warn( + f"{type(self).__name__}.mkdir(): parent_mode is currently ignored.", + UserWarning, + stacklevel=2, + ) if parents and not exist_ok and self.exists(): raise FileExistsError(str(self)) try: diff --git a/upath/extensions.py b/upath/extensions.py index 1e6389a6..df51e978 100644 --- a/upath/extensions.py +++ b/upath/extensions.py @@ -174,8 +174,13 @@ def mkdir( mode: int = 0o777, parents: bool = False, exist_ok: bool = False, + *, + parent_mode: int | None = None, ) -> None: - self.__wrapped__.mkdir(mode=mode, parents=parents, exist_ok=exist_ok) + kw: dict[str, Any] = {} + if parent_mode is not None: + kw["parent_mode"] = parent_mode + self.__wrapped__.mkdir(mode=mode, parents=parents, exist_ok=exist_ok, **kw) def __open_writer__(self, mode: Literal["a", "w", "x"]) -> BinaryIO: return self.__wrapped__.__open_writer__(mode) diff --git a/upath/implementations/cloud.py b/upath/implementations/cloud.py index 0f76b4c1..590e899c 100644 --- a/upath/implementations/cloud.py +++ b/upath/implementations/cloud.py @@ -97,11 +97,18 @@ def parts(self) -> Sequence[str]: return parts def mkdir( - self, mode: int = 0o777, parents: bool = False, exist_ok: bool = False + self, + mode: int = 0o777, + parents: bool = False, + exist_ok: bool = False, + *, + parent_mode: int | None = None, ) -> None: if not parents and not exist_ok and self.exists(): raise FileExistsError(self.path) - super().mkdir(mode=mode, parents=parents, exist_ok=exist_ok) + super().mkdir( + mode=mode, parents=parents, exist_ok=exist_ok, parent_mode=parent_mode + ) class GCSPath(CloudPath): @@ -121,10 +128,17 @@ def __init__( raise ValueError("non key-like path provided (bucket/container missing)") def mkdir( - self, mode: int = 0o777, parents: bool = False, exist_ok: bool = False + self, + mode: int = 0o777, + parents: bool = False, + exist_ok: bool = False, + *, + parent_mode: int | None = None, ) -> None: try: - super().mkdir(mode=mode, parents=parents, exist_ok=exist_ok) + super().mkdir( + mode=mode, parents=parents, exist_ok=exist_ok, parent_mode=parent_mode + ) except TypeError as err: if "unexpected keyword argument 'create_parents'" in str(err): self.fs.mkdir(self.path) @@ -227,6 +241,8 @@ def mkdir( mode: int = 0o777, parents: bool = False, exist_ok: bool = False, + *, + parent_mode: int | None = None, ) -> None: raise UnsupportedOperation diff --git a/upath/implementations/data.py b/upath/implementations/data.py index 0b8dfdc1..8d30f97c 100644 --- a/upath/implementations/data.py +++ b/upath/implementations/data.py @@ -93,7 +93,12 @@ def full_match(self, pattern, *, case_sensitive: bool | None = None) -> bool: return super().full_match(pattern, case_sensitive=case_sensitive) def mkdir( - self, mode: int = 0o777, parents: bool = False, exist_ok: bool = False + self, + mode: int = 0o777, + parents: bool = False, + exist_ok: bool = False, + *, + parent_mode: int | None = None, ) -> None: raise FileExistsError(str(self)) diff --git a/upath/implementations/ftp.py b/upath/implementations/ftp.py index 6f383245..2e9663ab 100644 --- a/upath/implementations/ftp.py +++ b/upath/implementations/ftp.py @@ -44,9 +44,11 @@ def mkdir( mode: int = 0o777, parents: bool = False, exist_ok: bool = False, + *, + parent_mode: int | None = None, ) -> None: try: - return super().mkdir(mode, parents, exist_ok) + return super().mkdir(mode, parents, exist_ok, parent_mode=parent_mode) except FTPPermanentError as e: if e.args[0].startswith("550") and exist_ok: return diff --git a/upath/implementations/github.py b/upath/implementations/github.py index 07e07ba4..87049324 100644 --- a/upath/implementations/github.py +++ b/upath/implementations/github.py @@ -66,6 +66,8 @@ def mkdir( mode: int = 0o777, parents: bool = False, exist_ok: bool = False, + *, + parent_mode: int | None = None, ) -> None: raise UnsupportedOperation diff --git a/upath/implementations/hdfs.py b/upath/implementations/hdfs.py index 368dff2e..98664082 100644 --- a/upath/implementations/hdfs.py +++ b/upath/implementations/hdfs.py @@ -34,8 +34,15 @@ def __init__( ) -> None: ... def mkdir( - self, mode: int = 0o777, parents: bool = False, exist_ok: bool = False + self, + mode: int = 0o777, + parents: bool = False, + exist_ok: bool = False, + *, + parent_mode: int | None = None, ) -> None: if not exist_ok and self.exists(): raise FileExistsError(str(self)) - super().mkdir(mode=mode, parents=parents, exist_ok=exist_ok) + super().mkdir( + mode=mode, parents=parents, exist_ok=exist_ok, parent_mode=parent_mode + ) diff --git a/upath/implementations/http.py b/upath/implementations/http.py index 02394375..b09e1471 100644 --- a/upath/implementations/http.py +++ b/upath/implementations/http.py @@ -134,6 +134,8 @@ def mkdir( mode: int = 0o777, parents: bool = False, exist_ok: bool = False, + *, + parent_mode: int | None = None, ) -> None: raise UnsupportedOperation diff --git a/upath/implementations/local.py b/upath/implementations/local.py index 884199d9..0170f13f 100644 --- a/upath/implementations/local.py +++ b/upath/implementations/local.py @@ -367,6 +367,48 @@ def rmdir(self, recursive: bool = UNSET_DEFAULT) -> None: else: shutil.rmtree(self) + if sys.version_info < (3, 15): + + def mkdir( + self, + mode: int = 0o777, + parents: bool = False, + exist_ok: bool = False, + *, + parent_mode: int | None = None, + ) -> None: + if parent_mode is None: + return super().mkdir(mode, parents, exist_ok) + # backport of the parent_mode argument added in python 3.15 + try: + super().mkdir(mode, parents=False, exist_ok=exist_ok) + except FileNotFoundError: + if not parents or self.parent == self: + raise + self.parent.mkdir( + mode=parent_mode, + parents=True, + exist_ok=True, + parent_mode=parent_mode, + ) + super().mkdir(mode, parents=False, exist_ok=exist_ok) + + else: + + def is_reserved(self) -> bool: + # pathlib.PurePath.is_reserved() was removed in python 3.15 + warnings.warn( + f"{type(self).__name__}.is_reserved() is deprecated. Use" + " os.path.isreserved() to detect reserved paths on Windows.", + DeprecationWarning, + stacklevel=2, + ) + if os.name == "nt": + import ntpath + + return ntpath.isreserved(self) + return False + # we need to override pathlib.Path._copy_from to support it as a # WritablePath._copy_from target with support for on_name_collision # Issue: https://github.com/barneygale/pathlib-abc/issues/48 diff --git a/upath/implementations/smb.py b/upath/implementations/smb.py index 956fdbad..e6b21849 100644 --- a/upath/implementations/smb.py +++ b/upath/implementations/smb.py @@ -58,6 +58,8 @@ def mkdir( mode: int = 0o777, parents: bool = False, exist_ok: bool = False, + *, + parent_mode: int | None = None, ) -> None: # smbclient does not support setting mode externally from smbprotocol.exceptions import SMBOSError diff --git a/upath/implementations/tar.py b/upath/implementations/tar.py index 8310a850..55046bf2 100644 --- a/upath/implementations/tar.py +++ b/upath/implementations/tar.py @@ -50,6 +50,8 @@ def mkdir( mode: int = 0o777, parents: bool = False, exist_ok: bool = False, + *, + parent_mode: int | None = None, ) -> None: raise UnsupportedOperation diff --git a/upath/implementations/zip.py b/upath/implementations/zip.py index 8d34b08e..14c955cb 100644 --- a/upath/implementations/zip.py +++ b/upath/implementations/zip.py @@ -51,6 +51,8 @@ def mkdir( mode: int = 0o777, parents: bool = False, exist_ok: bool = False, + *, + parent_mode: int | None = None, ) -> None: raise UnsupportedOperation diff --git a/upath/tests/cases.py b/upath/tests/cases.py index 22587fa9..9abfc3a4 100644 --- a/upath/tests/cases.py +++ b/upath/tests/cases.py @@ -767,6 +767,15 @@ def test_mkdir_parents_true_exists_ok_false(self): with pytest.raises(FileExistsError): new_dir.mkdir(parents=True, exist_ok=False) + def test_mkdir_parent_mode(self): + new_dir = self.path.joinpath("parent_mode", "new_dir") + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "parent_mode is currently ignored") + new_dir.mkdir(parents=True, parent_mode=0o755) + if not self.SUPPORTS_EMPTY_DIRS: + new_dir.joinpath(".file").touch() + assert new_dir.is_dir() + def test_touch_exists_ok_false(self): f = self.path.joinpath("file1.txt") assert f.exists() diff --git a/upath/tests/implementations/test_local.py b/upath/tests/implementations/test_local.py index aef91139..a77c256f 100644 --- a/upath/tests/implementations/test_local.py +++ b/upath/tests/implementations/test_local.py @@ -1,4 +1,6 @@ import os +import sys +import warnings from pathlib import Path import pytest @@ -9,6 +11,7 @@ from ..cases import BaseTests from ..utils import OverrideMeta from ..utils import overrides_base +from ..utils import skip_on_windows from ..utils import xfail_if_version @@ -60,3 +63,26 @@ def path(self, local_testdir): ) def test_local_paths_are_pathlike(protocol, path): assert isinstance(UPath(path, protocol=protocol), os.PathLike) + + +@skip_on_windows +def test_local_mkdir_parent_mode(tmp_path): + umask = os.umask(0) + try: + pth = UPath(tmp_path).joinpath("a", "b", "c") + pth.mkdir(mode=0o700, parents=True, parent_mode=0o750) + finally: + os.umask(umask) + assert pth.stat().st_mode & 0o777 == 0o700 + assert pth.parent.stat().st_mode & 0o777 == 0o750 + assert pth.parent.parent.stat().st_mode & 0o777 == 0o750 + + +def test_local_is_reserved(): + pth = UPath("file.txt") + with warnings.catch_warnings(): + warnings.simplefilter("ignore", DeprecationWarning) + assert pth.is_reserved() is False + if sys.version_info >= (3, 13): + with pytest.warns(DeprecationWarning): + pth.is_reserved() From 9c09e28ca81ec9aa29bcbc1d490ba47dbe0534ae Mon Sep 17 00:00:00 2001 From: Andreas Poehlmann Date: Mon, 9 Nov 2026 22:34:29 +0100 Subject: [PATCH 2/2] typesafety: accept generic SplitResult revealed on python 3.15 The typeshed bundled for python 3.15 makes urllib.parse.SplitResult generic, so mypy reveals UPath._url as SplitResult[str]. Accept both forms, with and without the builtins prefix. --- typesafety/test_upath_interface.yml | 2 +- typesafety/test_upath_signatures.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/typesafety/test_upath_interface.yml b/typesafety/test_upath_interface.yml index 06dcd037..45a5f1bd 100644 --- a/typesafety/test_upath_interface.yml +++ b/typesafety/test_upath_interface.yml @@ -54,7 +54,7 @@ from upath import UPath p = UPath("abc") - reveal_type(p._url) # NR: Revealed type is "[Tt]uple\[builtins.str, builtins.str, builtins.str, builtins.str, builtins.str, fallback=urllib.parse.SplitResult\]" + reveal_type(p._url) # NR: Revealed type is "[Tt]uple\[(builtins\.)?str, (builtins\.)?str, (builtins\.)?str, (builtins\.)?str, (builtins\.)?str, fallback=urllib.parse.SplitResult(\[(builtins\.)?str\])?\]" # === upath pathlib.PurePath interface ================================ diff --git a/typesafety/test_upath_signatures.yml b/typesafety/test_upath_signatures.yml index 8a73bc72..0d69fd02 100644 --- a/typesafety/test_upath_signatures.yml +++ b/typesafety/test_upath_signatures.yml @@ -219,7 +219,7 @@ from upath import UPath p = UPath("") - reveal_type(p._url) # N: Revealed type is "tuple[builtins.str, builtins.str, builtins.str, builtins.str, builtins.str, fallback=urllib.parse.SplitResult]" + reveal_type(p._url) # NR: Revealed type is "tuple\[(builtins\.)?str, (builtins\.)?str, (builtins\.)?str, (builtins\.)?str, (builtins\.)?str, fallback=urllib.parse.SplitResult(\[(builtins\.)?str\])?\]" # FIXME fsspec types are not available # - case: upath_attribute_fs