Implement pure Path properties: drive, root, anchor, is_reserved, and match

Merged
GA
12d ago
+236-7

Description

Implements standard pure pathlib.Path properties and methods (drive, root, anchor, is_reserved(), and match()), closing compatibility gaps identified in #1060 and documented in limitations/pathlib.md.

Context: Downstream commit BucketHeadP65/ai-studio@b0ec4fa documented these missing attributes as active compatibility blockers in sandboxed agent workflows.

Summary of Changes:

  • Path.drive: Returns "" for POSIX paths.
  • Path.root: Returns "/" for absolute paths and "" for relative paths.
  • Path.anchor: Returns "/" for absolute paths and "" for relative paths (drive + root).
  • Path.is_reserved(): Returns False on POSIX systems; validates argument arity (takes 0 arguments).
  • Path.match(path_pattern, *, case_sensitive=None): Matches paths against glob-style wildcard patterns using SegmentPattern with CPython 3.14 component-wise matching semantics and case-sensitivity handling.
  • intern.rs: Registered Anchor, Drive, IsReserved, PathPattern, and Root in StaticStrings.
  • limitations/pathlib.md: Updated documentation of pure methods and visible argument arity count.
  • pathlib__pure.py: Added test cases verifying parity with CPython across all new attributes, methods, edge cases, and argument errors.

Summary by cubic

Implements the pure pathlib.Path properties drive, root, anchor and the is_reserved() and match() methods, closing compatibility gaps identified in #1060 and documented in limitations/pathlib.md.

  • drive is always "" on POSIX; root and anchor return "/" for absolute paths and "" otherwise; is_reserved() always returns False and rejects extra arguments.
  • match() follows CPython 3.14 component-wise matching via SegmentPattern, supports the case_sensitive keyword, and raises ValueError: empty pattern for empty patterns ("", ".").
  • Root matching is strict, so Path('/').match('*') returns False, matching CPython; match() also accepts Path objects as patterns and raises TypeError for other types.
  • SegmentPattern polls the ResourceTracker to cap backtracking on pathological patterns and documents the ResourceError it can raise.