[New-bugs-announce] [issue38624] pathlib .suffix, .suffixes, .stem unexpected behavior for pathname with trailing dot

Inyeol Lee report at bugs.python.org
Mon Oct 28 18:54:26 EDT 2019


New submission from Inyeol Lee <inyeol.lee at gmail.com>:

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.

----------
components: Library (Lib)
messages: 355600
nosy: inyeollee
priority: normal
severity: normal
status: open
title: pathlib .suffix, .suffixes, .stem unexpected behavior for pathname with trailing dot
type: behavior
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38624>
_______________________________________


More information about the New-bugs-announce mailing list