-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
consistent result of basename
for dir path
#33000
Comments
For reference, |
The POSIX basename(2) says to ignore trailing slashes before calculating the basename |
julia's basename matches python's behavior. Also changing this is breaking. Personally I don't see any issues with Julia's behavior with this function. Further documentation clarifying it's behavior would also close this issue. |
I think it's more like a bug because other related functions in Julia ignores the trailing "/". Python's In [4]: import os
In [5]: os.path.split("/opt/")
Out[5]: ('/opt', '')
In [6]: os.path.split("/opt")
Out[6]: ('/', 'opt') Julia: julia> splitpath("/opt/")
2-element Array{String,1}:
"/"
"opt"
julia> splitpath("/opt")
2-element Array{String,1}:
"/"
"opt" |
The issue here is regarding the behavior |
Looks like Python's split path just splits it into a tuple of a head and tail, which is different than in Julia where it's split into a Vector of path components. So the equivalent in Julia would be:
In which case, we match the Python behavior. Unrelated: I kinda question the utility of |
The only thing to decide here is whether the current behavior is desired and if so, document it. The current behavior is valid, but perhaps not desired in all cases, but there is nothing wrong with the answer and as mentioned Python's function behaves the same. I don't necessarily see the precedent with Python's |
Although
basename(path)
is designed to split file name out frompath
, it doesn't check if the path is a valid file. That's to say, we can still use it to split folder name out frompath
as well.Since there're two valid usages of dir path, it's expected to get the same results:
This is tested on
1.0.4
,1.1.1
, and1.2.0
The text was updated successfully, but these errors were encountered: