This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: pathlib .suffix, .suffixes, .stem unexpected behavior for pathname with trailing dot
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: inyeollee, pitrou
Priority: normal Keywords:

Created on 2019-10-28 22:54 by inyeollee, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg355600 - (view) Author: Inyeol Lee (inyeollee) Date: 2019-10-28 22:54
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.
History
Date User Action Args
2022-04-11 14:59:22adminsetgithub: 82805
2019-10-29 01:59:29xtreaksetnosy: + pitrou
2019-10-28 22:54:26inyeolleecreate