feat(stdlib): add pathlib module bindings#276
Merged
Conversation
Adds F# bindings for Python's pathlib.Path class: - Path construction (single string and multi-segment) - Properties: name, stem, suffix, suffixes, parent, parents, parts, root, anchor, drive - Path arithmetic: / operator (string and Path), joinpath - Pure transformations: with_name, with_stem, with_suffix, as_posix, as_uri - I/O predicates: exists, is_file, is_dir, is_symlink, is_mount, is_absolute - I/O operations: resolve, relative_to, read_text, read_bytes, write_text, write_bytes - Directory operations: mkdir, mkdir_p, rmdir, iterdir, glob, rglob - File operations: unlink, rename, replace, expanduser - Static factories: Path.cwd, Path.home - is_relative_to (3.9+) Includes 36 tests covering construction, properties, path arithmetic, transformations, predicates, file round-trips, and directory operations. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Fable emits primary-ctor parameters as Python kwargs, but pathlib.Path.__init__ does not accept `path=` as a keyword, breaking 27 tests with `TypeError: PurePath.__init__() got an unexpected keyword argument 'path'`. Switch to a no-arg primary ctor and declare the string and varargs ctors via [<Emit>] so emission stays positional. Also relax suffixes/parents/parts to `seq<_>` to match the underlying tuple/list/_PathParents return types, and wrap the byte fixture in builtins.bytes so write_bytes receives a real bytes object instead of a fable.UInt8Array. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
# Conflicts: # src/Fable.Python.fsproj # test/Fable.Python.Test.fsproj
Lost during the merge conflict resolution. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is an automated pull request from Repo Assist, an AI assistant for this repository.
Summary
Adds F# bindings for Python's [
pathlib]((docs.python.org/redacted) module — the modern, object-oriented path-handling library introduced in Python 3.4 and now preferred overos.path.The core class is
pathlib.Path, which Fable.Python users can now use directly from F#.What's included
src/stdlib/Pathlib.fsConstruction
Path(string)— single-segment constructorPath(string[])— multi-segment constructor (varargs)Path.cwd()/Path.home()— static factory methodsProperties (all pure, no I/O)
name,stem,suffix,suffixes,parent,parents,parts,root,anchor,drivePath arithmetic
/operator (Path / stringandPath / Path)joinpath(parts...)— varargs joinPure transformations
with_name,with_stem(3.9+),with_suffixas_posix,as_uriis_absolute,is_relative_to(3.9+, string and Path overloads)I/O predicates
exists,is_file,is_dir,is_symlink,is_mountFile I/O
read_text()/read_text(encoding),read_bytes()write_text(data)/write_text(data, encoding),write_bytes(data)Directory and file operations
mkdir(),mkdir(mode, parents, exist_ok),mkdir_p()(creates all parents)rmdir(),unlink(),unlink(missing_ok)rename(target),replace(target)— Path and string overloadsresolve(),relative_to(other)— Path and string overloadsexpanduser()iterdir(),glob(pattern),rglob(pattern)test/TestPathlib.fs— 36 testsCovers: construction, properties, path arithmetic, transformations, predicates, file round-trips (
write_text/read_text,write_bytes/read_bytes), directory operations (mkdir_p,rmdir,iterdir), and glob.Trade-offs
Pathis bound (notPurePath,PurePosixPath,PureWindowsPath,PosixPath,WindowsPath). Those can be added later if needed;Pathcovers the vast majority of use cases.open()is intentionally omitted — F# idiomatic I/O viaread_text/write_text/read_bytes/write_bytesis cleaner.Usage example
Note
🔒 Integrity filter blocked 10 items
The following items were blocked because they don't meet the GitHub integrity level.
list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".To allow these resources, lower
min-integrityin your GitHub frontmatter: