Skip to content
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

pathlib .suffix, .suffixes, .stem unexpected behavior for pathname with trailing dot #82805

Open
inyeollee mannequin opened this issue Oct 28, 2019 · 1 comment
Open

pathlib .suffix, .suffixes, .stem unexpected behavior for pathname with trailing dot #82805

inyeollee mannequin opened this issue Oct 28, 2019 · 1 comment
Labels
3.8 expert-pathlib stdlib type-bug

Comments

@inyeollee
Copy link
Mannequin

@inyeollee inyeollee mannequin commented Oct 28, 2019

BPO 38624
Nosy @pitrou

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2019-10-28.22:54:26.232>
labels = ['3.8', 'type-bug', 'library']
title = 'pathlib .suffix, .suffixes, .stem unexpected behavior for pathname with trailing dot'
updated_at = <Date 2019-10-29.01:59:29.319>
user = 'https://bugs.python.org/inyeollee'

bugs.python.org fields:

activity = <Date 2019-10-29.01:59:29.319>
actor = 'xtreak'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2019-10-28.22:54:26.232>
creator = 'inyeollee'
dependencies = []
files = []
hgrepos = []
issue_num = 38624
keywords = []
message_count = 1.0
messages = ['355600']
nosy_count = 2.0
nosy_names = ['pitrou', 'inyeollee']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue38624'
versions = ['Python 3.8']

@inyeollee
Copy link
Mannequin Author

@inyeollee inyeollee mannequin commented Oct 28, 2019

Python3.8 pathlib treats dot between path stem and suffix as part of suffix in general:

>>> a = pathlib.Path('foo.txt')
>>> a.stem, a.suffix
('foo', '.txt')
>>> a.with_suffix('')
PosixPath('foo')

However, if pathname ends with dot, it treats the trailing dot as part of stem, not part of suffix:

>>> b = pathlib.Path('bar.')
>>> b.stem, b.suffix
('bar.', '')

This looks like a bug. It should return ('bar', '.').
There are couple of unexpected behavior related to this:

>>> pathlib.Path('foo.txt').with_suffix('.')
...
ValueError: Invalid suffix '.' <== Why not PosixPath('foo.') ?
>>> c = pathlib.Path('foo..')
>>> c.stem, c.suffix, c.suffixes
('foo..', '', [])

I think above should return ('foo.', '.', ['.', '.'])

Tested with macOS 10.15 and Python3.8. Python3.7 behaves the same.

@inyeollee inyeollee mannequin added 3.8 stdlib type-bug labels Oct 28, 2019
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.8 expert-pathlib stdlib type-bug
Projects
None yet
Development

No branches or pull requests

1 participant