Implement pure Path properties: drive, root, anchor, is_reserved, and match
Merged
GA
12d ago+236+236+012345678901234567890123456789-7-7-0123456789
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(): ReturnsFalseon POSIX systems; validates argument arity (takes 0 arguments).Path.match(path_pattern, *, case_sensitive=None): Matches paths against glob-style wildcard patterns usingSegmentPatternwith CPython 3.14 component-wise matching semantics and case-sensitivity handling.intern.rs: RegisteredAnchor,Drive,IsReserved,PathPattern, andRootinStaticStrings.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.
driveis always""on POSIX;rootandanchorreturn"/"for absolute paths and""otherwise;is_reserved()always returnsFalseand rejects extra arguments.match()follows CPython 3.14 component-wise matching viaSegmentPattern, supports thecase_sensitivekeyword, and raisesValueError: empty patternfor empty patterns ("",".").- Root matching is strict, so
Path('/').match('*')returnsFalse, matching CPython;match()also acceptsPathobjects as patterns and raisesTypeErrorfor other types. SegmentPatternpolls theResourceTrackerto cap backtracking on pathological patterns and documents theResourceErrorit can raise.