Skip to content

[ruff, flake8-use-pathlib] Support parent_mode (RUF064, PTH103) - #28528

Merged
ntBre merged 1 commit into
mainfrom
brent/parent-mode
Sep 14, 2026
Merged

ntBre merged 1 commit into
mainfrom
brent/parent-mode

Conversation

@ntBre

@ntBre ntBre commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Python 3.15 adds the parent_mode argument to both os.makedirs and pathlib.Path.mkdir, which allows setting the mode for intermediate directories separately from the main mode argument. This PR adds support for the new argument in both non-octal-permissions (RUF064), which now checks this argument's permissions too, and in os-makedirs (PTH103), which just needs to recognize it for converting calls from the os to the pathlib versions.

As a note to head off other Codexes, my Codex keeps complaining about this fix being unsafe:

 import os
+import pathlib

 def create():
-    os.makedirs("a/b", parent_mode=(mode := 0o700), mode=mode)
+    pathlib.Path("a/b").mkdir(mode=mode, parents=True, parent_mode=(mode := 0o700))

because it reorders the arguments and could change the order of side effects. This is yet another preexisting issue with the way this rule and a couple of other PTH rules rewrite argument lists that hasn't been reported and isn't strictly related to the 3.15 changes. If we're really worried about that, we could just mark the fix unsafe, I guess.

Test Plan

New mdtests for both affected rules

…03`)

Summary
--

Python 3.15 adds the `parent_mode` argument to both [`os.makedirs`] and [`pathlib.Path.mkdir`],
which allows setting the mode for intermediate directories separately from the main `mode` argument.
This PR adds support for the new argument in both [`non-octal-permissions` (`RUF064`)], which now
checks this argument's permissions too, and in [`os-makedirs` (`PTH103`)], which just needs to
recognize it for converting calls from the `os` to the `pathlib` versions.

[`os-makedirs` (`PTH103`)]: https://docs.astral.sh/ruff/rules/os-makedirs/
[`non-octal-permissions` (`RUF064`)]: https://docs.astral.sh/ruff/rules/non-octal-permissions/
[`pathlib.Path.mkdir`]: https://docs.python.org/3.15/library/pathlib.html#pathlib.Path.mkdir
[`os.makedirs`]: https://docs.python.org/3.15/library/os.html#os.makedirs

Test Plan
--

New mdtests for both affected rules
@ntBre ntBre added rule Implementing or modifying a lint rule python315 Related to Python 3.15 labels Sep 11, 2026
@ntBre ntBre mentioned this pull request Sep 11, 2026
27 of 32 tasks
@astral-sh-bot

astral-sh-bot Bot commented Sep 11, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@ntBre
ntBre marked this pull request as ready for review September 11, 2026 18:08
@ntBre
ntBre requested a review from MichaReiser September 11, 2026 18:08
@ntBre
ntBre merged commit 7981ff5 into main Sep 14, 2026
50 checks passed
@ntBre
ntBre deleted the brent/parent-mode branch September 14, 2026 13:23
carljm added a commit that referenced this pull request Sep 14, 2026
…aliases

* origin/main: (21 commits)
  [ty] Share attribute write compatibility checks (#28555)
  [ty] Prefer `ty.toml` and `pyproject.toml` over playground `ty.json` (#28449)
  [`ruff`, `flake8-use-pathlib`] Support `parent_mode` (`RUF064`, `PTH103`) (#28528)
  [`pyupgrade`] Make the fix for `UP040` always unsafe (#28526)
  [`pyupgrade`] Skip `TypeVarTuple` and `ParamSpec` conversions with bounds or constraints (`UP040`, `UP046`, `UP047`) (#28505)
  [ty] Escape glob characters in anchored directory paths (#28518)
  [ty] Handle gradual metaclass ancestry and conflicts (#28474)
  [ty] Preserve recursive metadata in union transformations (#28497)
  [ty] Refactor "desperate" import resolution to use candidate operations that will also apply to module enumeration. (#28543)
  [ty] Report override conflicts introduced by new bases (#28530)
  [ty] Resolve dependencies within correlated inference alternatives (#28252)
  [ty] Extract shared abstract-method analysis (#28537)
  [ty] Reject reassignment of enum members (#28462)
  [ty] Preserve runtime comparison semantics when narrowing tagged unions (#28053)
  [ty] Extract a method on `NameResolver` to advance resolution by single module name component. (#28540)
  [ty] Return root discovery to `NameResolver`, but retain necessary interface changes (#28536)
  [ty] Default-specialize class objects in meta-protocol checks (#28265)
  [ty] Extract module root discovery from `NameResolver`. (#28531)
  [ty] Fix MRO ordering for generic bases (#28172)
  [ty] Run benchmarks for auto-imports in CI (#28490)
  ...

# Conflicts:
#	crates/ty_python_semantic/src/types/narrow.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python315 Related to Python 3.15 rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants