-
Notifications
You must be signed in to change notification settings - Fork 19
Drop string subtyping #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f061620
1993958
d0a5d26
53ba6ce
007e189
7cdada9
550399b
c2ae0a1
bc802d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -249,14 +249,14 @@ Base.isempty(path::AbstractPath) = isempty(parts(path)) | |
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All uses of
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking it might be better to just overload |
||
| Returns whether the path actually exists on the system. | ||
| """ | ||
| exists(path::AbstractPath) = ispath(String(path)) | ||
| exists(path::AbstractPath) = ispath(string(path)) | ||
|
|
||
| """ | ||
| real(path::AbstractPath) -> AbstractPath | ||
|
|
||
| Canonicalizes a path by expanding symlinks and removing "." and ".." entries. | ||
| """ | ||
| Base.real(path::AbstractPath) = Path(realpath(String(path))) | ||
| Base.real(path::AbstractPath) = Path(realpath(string(path))) | ||
|
|
||
| """ | ||
| norm(path::AbstractPath) -> AbstractPath | ||
|
|
@@ -351,8 +351,8 @@ end | |
| The following a descriptive methods for paths | ||
| built around stat | ||
| =# | ||
| Base.stat(path::AbstractPath) = Status(stat(String(path))) | ||
| Base.lstat(path::AbstractPath) = Status(lstat(String(path))) | ||
| Base.stat(path::AbstractPath) = Status(stat(string(path))) | ||
| Base.lstat(path::AbstractPath) = Status(lstat(string(path))) | ||
|
|
||
| """ | ||
| mode(path::AbstractPath) -> Mode | ||
|
|
@@ -469,7 +469,7 @@ code in the implementation instances. | |
| TODO: Document these once we're comfortable with them. | ||
| =# | ||
|
|
||
| Base.cd(path::AbstractPath) = cd(String(path)) | ||
| Base.cd(path::AbstractPath) = cd(string(path)) | ||
| function Base.cd(fn::Function, dir::AbstractPath) | ||
| old = cwd() | ||
| try | ||
|
|
@@ -495,8 +495,8 @@ function Base.mkdir(path::AbstractPath; mode=0o777, recursive=false, exist_ok=fa | |
| end | ||
| end | ||
|
|
||
| VERSION >= v"0.7-" ? mkdir(String(path), mode=mode) : mkdir(String(path), mode) | ||
|
|
||
| VERSION >= v"0.7-" ? mkdir(string(path), mode=mode) : mkdir(string(path), mode) | ||
|
|
||
| end | ||
| end | ||
|
|
@@ -508,7 +508,7 @@ function Base.symlink(src::AbstractPath, dest::AbstractPath; exist_ok=false, ove | |
| end | ||
|
|
||
| if !exists(dest) | ||
| symlink(String(src), String(dest)) | ||
| symlink(string(src), string(dest)) | ||
| elseif !exist_ok | ||
| error("$dest already exists.") | ||
| end | ||
|
|
@@ -552,7 +552,7 @@ function move(src::AbstractPath, dest::AbstractPath; recursive=false, exist_ok=f | |
| mkdir(parent(dest); recursive=recursive, exist_ok=true) | ||
| end | ||
|
|
||
| mv(String(src), String(dest)) | ||
| mv(string(src), string(dest)) | ||
| elseif !exist_ok | ||
| error("$dest already exists.") | ||
| end | ||
|
|
@@ -562,21 +562,21 @@ function move(src::AbstractPath, dest::AbstractPath; recursive=false, exist_ok=f | |
| end | ||
|
|
||
| function Base.cp(src::AbstractPath, dest::AbstractPath; force::Bool=false, follow_symlinks::Bool=false) | ||
| Compat.cp(String(src), String(dest); force=force, follow_symlinks=follow_symlinks) | ||
| Compat.cp(string(src), string(dest); force=force, follow_symlinks=follow_symlinks) | ||
| end | ||
|
|
||
| remove(path::AbstractPath; recursive=false) = rm(String(path); recursive=recursive) | ||
| Base.touch(path::AbstractPath) = touch(String(path)) | ||
| remove(path::AbstractPath; recursive=false) = rm(string(path); recursive=recursive) | ||
| Base.touch(path::AbstractPath) = touch(string(path)) | ||
|
|
||
| tmpname() = Path(tempname()) | ||
| tmpdir() = Path(tempdir()) | ||
|
|
||
| function mktmp(parent::AbstractPath=Path(tempdir())) | ||
| path, io = mktemp(String(parent)) | ||
| path, io = mktemp(string(parent)) | ||
| return Path(path), io | ||
| end | ||
|
|
||
| mktmpdir(parent::AbstractPath=tmpdir()) = Path(mktempdir(String(parent))) | ||
| mktmpdir(parent::AbstractPath=tmpdir()) = Path(mktempdir(string(parent))) | ||
|
|
||
| function mktmp(fn::Function, parent=tmpdir()) | ||
| (tmp_path, tmp_io) = mktmp(parent) | ||
|
|
@@ -608,7 +608,7 @@ function Base.chown(path::AbstractPath, user::AbstractString, group::AbstractStr | |
| if recursive | ||
| push!(chown_cmd, "-R") | ||
| end | ||
| append!(chown_cmd, String["$(user):$(group)", String(path)]) | ||
| append!(chown_cmd, String["$(user):$(group)", string(path)]) | ||
|
|
||
| run(Cmd(chown_cmd)) | ||
| else | ||
|
|
@@ -654,7 +654,7 @@ julia> mode(p"newfile") | |
| ``` | ||
| """ | ||
| function Base.chmod(path::AbstractPath, mode::Mode; recursive=false) | ||
| chmod_path = String(path) | ||
| chmod_path = string(path) | ||
| chmod_mode = raw(mode) | ||
|
|
||
| if isdir(path) && recursive | ||
|
|
@@ -725,20 +725,25 @@ function Base.chmod(path::AbstractPath, symbolic_mode::AbstractString; recursive | |
| end | ||
| end | ||
|
|
||
| Base.read(path::AbstractPath) = read(String(path), String) | ||
| Base.open(path::AbstractPath, args...) = open(string(path), args...) | ||
| function Base.open(f::Function, path::AbstractPath, args...; kwargs...) | ||
| open(f, string(path), args...; kwargs...) | ||
| end | ||
|
|
||
| Base.read(path::AbstractPath) = read(string(path), String) | ||
|
|
||
| function Base.write(path::AbstractPath, content::AbstractString, mode="w") | ||
| open(String(path), mode) do f | ||
| open(path, mode) do f | ||
| write(f, content) | ||
| end | ||
| end | ||
|
|
||
| Base.readlink(path::AbstractPath) = Path(readlink(String(path))) | ||
| Base.readdir(path::AbstractPath) = map(Path, readdir(String(path))) | ||
| Base.readlink(path::AbstractPath) = Path(readlink(string(path))) | ||
| Base.readdir(path::AbstractPath) = map(Path, readdir(string(path))) | ||
|
|
||
| function Base.download(src::AbstractString, dest::AbstractPath, overwrite::Bool=false) | ||
| if !exists(dest) || overwrite | ||
| download(src, String(dest)) | ||
| download(src, string(dest)) | ||
| end | ||
| return dest | ||
| end | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be
String(x)notstring(x).Both semantically, and because
string(x)gives the wrong result.(at least with the previous version, you have changed this now maybe?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's changing with the
showandprintchanges.While this achieves what I'd like, I'm not sure it's the correct way to handle that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String(p)feels more semantic to me.It feels like a shorthand for
convert(String, p)Where as
string(p)to me reads like "Give me some thing I could show a user".Since it is tied to just being
print.Further, I think some
AbstractPathsmay want to overload theirprintin other ways.Since
printis pretty freefrom in what you do.Like an
S3Pathmight want to actually display the URL rather than (just) the path.