Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
2f456582
Commit
2f456582
authored
Jan 06, 2016
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #22570: Add 'path' attribute to pathlib.Path objects.
parent
56990a79
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
0 deletions
+40
-0
Lib/pathlib.py
Lib/pathlib.py
+7
-0
Lib/test/test_pathlib.py
Lib/test/test_pathlib.py
+27
-0
Misc/NEWS
Misc/NEWS
+6
-0
No files found.
Lib/pathlib.py
View file @
2f456582
...
...
@@ -645,6 +645,13 @@ class PurePath(object):
self
.
_parts
)
or
'.'
return
self
.
_str
@
property
def
path
(
self
):
try
:
return
self
.
_str
except
AttributeError
:
return
str
(
self
)
def
as_posix
(
self
):
"""Return the string representation of the path with forward (/)
slashes."""
...
...
Lib/test/test_pathlib.py
View file @
2f456582
...
...
@@ -480,6 +480,22 @@ class _BasePurePathTest(object):
self
.
assertEqual
(
P
(
'a/b.py'
).
name
,
'b.py'
)
self
.
assertEqual
(
P
(
'/a/b.py'
).
name
,
'b.py'
)
def
test_path_common
(
self
):
P
=
self
.
cls
def
check
(
arg
,
expected
=
None
):
if
expected
is
None
:
expected
=
arg
self
.
assertEqual
(
P
(
arg
).
path
,
expected
.
replace
(
'/'
,
self
.
sep
))
check
(
''
,
'.'
)
check
(
'.'
)
check
(
'/'
)
check
(
'a/b'
)
check
(
'/a/b'
)
check
(
'/a/b/'
,
'/a/b'
)
check
(
'/a/b/.'
,
'/a/b'
)
check
(
'a/b.py'
)
check
(
'/a/b.py'
)
def
test_suffix_common
(
self
):
P
=
self
.
cls
self
.
assertEqual
(
P
(
''
).
suffix
,
''
)
...
...
@@ -903,6 +919,17 @@ class PureWindowsPathTest(_BasePurePathTest, unittest.TestCase):
self
.
assertEqual
(
P
(
'//My.py/Share.php'
).
name
,
''
)
self
.
assertEqual
(
P
(
'//My.py/Share.php/a/b'
).
name
,
'b'
)
def
test_path
(
self
):
P
=
self
.
cls
self
.
assertEqual
(
P
(
'c:'
).
path
,
'c:'
)
self
.
assertEqual
(
P
(
'c:/'
).
path
,
'c:
\
\
'
)
self
.
assertEqual
(
P
(
'c:a/b'
).
path
,
'c:a
\
\
b'
)
self
.
assertEqual
(
P
(
'c:/a/b'
).
path
,
'c:
\
\
a
\
\
b'
)
self
.
assertEqual
(
P
(
'c:a/b.py'
).
path
,
'c:a
\
\
b.py'
)
self
.
assertEqual
(
P
(
'c:/a/b.py'
).
path
,
'c:
\
\
a
\
\
b.py'
)
self
.
assertEqual
(
P
(
'//My.py/Share.php'
).
path
,
'
\
\
\
\
My.py
\
\
Share.php
\
\
'
)
self
.
assertEqual
(
P
(
'//My.py/Share.php/a/b'
).
path
,
'
\
\
\
\
My.py
\
\
Share.php
\
\
a
\
\
b'
)
def
test_suffix
(
self
):
P
=
self
.
cls
self
.
assertEqual
(
P
(
'c:'
).
suffix
,
''
)
...
...
Misc/NEWS
View file @
2f456582
...
...
@@ -13,6 +13,12 @@ Core and Builtins
Library
-------
- Issue #22570: Add '
path
' attribute to pathlib.Path objects,
returning the same as str(), to make it more similar to DirEntry.
Library code can now write getattr(p, '
path
', p) to get the path as
a string from a Path, a DirEntry, or a plain string. This is
essentially a small one-off protocol.
- Issue #26012: Don'
t
traverse
into
symlinks
for
**
pattern
in
pathlib
.
Path
.[
r
]
glob
().
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment