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
e50dafcd
Commit
e50dafcd
authored
Jul 06, 2014
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #20639: calling Path.with_suffix('') allows removing the suffix again.
Patch by July Tikhonov.
parent
7084e736
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
4 deletions
+12
-4
Lib/pathlib.py
Lib/pathlib.py
+3
-4
Lib/test/test_pathlib.py
Lib/test/test_pathlib.py
+6
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/pathlib.py
View file @
e50dafcd
...
...
@@ -759,11 +759,10 @@ class PurePath(object):
def
with_suffix
(
self
,
suffix
):
"""Return a new path with the file suffix changed (or added, if none)."""
# XXX if suffix is None, should the current suffix be removed?
drv
,
root
,
parts
=
self
.
_flavour
.
parse_parts
((
suffix
,))
if
drv
or
root
or
len
(
parts
)
!=
1
:
f
=
self
.
_flavour
if
f
.
sep
in
suffix
or
f
.
altsep
and
f
.
altsep
in
suffix
:
raise
ValueError
(
"Invalid suffix %r"
%
(
suffix
))
suffix
=
parts
[
0
]
if
not
suffix
.
startswith
(
'.'
):
if
suffix
and
not
suffix
.
startswith
(
'.'
)
or
suffix
==
'.'
:
raise
ValueError
(
"Invalid suffix %r"
%
(
suffix
))
name
=
self
.
name
if
not
name
:
...
...
Lib/test/test_pathlib.py
View file @
e50dafcd
...
...
@@ -551,6 +551,9 @@ class _BasePurePathTest(object):
self
.
assertEqual
(
P
(
'/a/b'
).
with_suffix
(
'.gz'
),
P
(
'/a/b.gz'
))
self
.
assertEqual
(
P
(
'a/b.py'
).
with_suffix
(
'.gz'
),
P
(
'a/b.gz'
))
self
.
assertEqual
(
P
(
'/a/b.py'
).
with_suffix
(
'.gz'
),
P
(
'/a/b.gz'
))
# Stripping suffix
self
.
assertEqual
(
P
(
'a/b.py'
).
with_suffix
(
''
),
P
(
'a/b'
))
self
.
assertEqual
(
P
(
'/a/b'
).
with_suffix
(
''
),
P
(
'/a/b'
))
# Path doesn't have a "filename" component
self
.
assertRaises
(
ValueError
,
P
(
''
).
with_suffix
,
'.gz'
)
self
.
assertRaises
(
ValueError
,
P
(
'.'
).
with_suffix
,
'.gz'
)
...
...
@@ -558,9 +561,12 @@ class _BasePurePathTest(object):
# Invalid suffix
self
.
assertRaises
(
ValueError
,
P
(
'a/b'
).
with_suffix
,
'gz'
)
self
.
assertRaises
(
ValueError
,
P
(
'a/b'
).
with_suffix
,
'/'
)
self
.
assertRaises
(
ValueError
,
P
(
'a/b'
).
with_suffix
,
'.'
)
self
.
assertRaises
(
ValueError
,
P
(
'a/b'
).
with_suffix
,
'/.gz'
)
self
.
assertRaises
(
ValueError
,
P
(
'a/b'
).
with_suffix
,
'c/d'
)
self
.
assertRaises
(
ValueError
,
P
(
'a/b'
).
with_suffix
,
'.c/.d'
)
self
.
assertRaises
(
ValueError
,
P
(
'a/b'
).
with_suffix
,
'./.d'
)
self
.
assertRaises
(
ValueError
,
P
(
'a/b'
).
with_suffix
,
'.d/.'
)
def
test_relative_to_common
(
self
):
P
=
self
.
cls
...
...
Misc/NEWS
View file @
e50dafcd
...
...
@@ -27,6 +27,9 @@ Core and Builtins
Library
-------
- Issue #20639: calling Path.with_suffix('') allows removing the suffix
again. Patch by July Tikhonov.
- Issue #21714: Disallow the construction of invalid paths using
Path.with_name(). Original patch by Antony Lee.
...
...
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