[docs] [issue25433] whitespace in strip()/lstrip()/rstrip()

Ulf Rompe report at bugs.python.org
Sat Jul 13 14:38:27 EDT 2019


Ulf Rompe <ulf at rompe.org> added the comment:

Using a re.sub() call as documentation:

1. wouldn't be helpful for many developers. If they need to look up the documentation of a simple method they shouldn't be forced to learn about a more complex one as well to understand it.
2. would be wild guessing since the re module defines its own whitespace as well.

I have created a pull request that aligns the strip methods of bytearray to those of bytes objects. The implementation found there is cleaner and even a little bit faster.

Current master:

./python -m timeit -s 'bla = bytearray(b"  foo  ")' 'bla.lstrip()'
1000000 loops, best of 5: 245 nsec per loop
./python -m timeit -s 'bla = bytearray(b"  foo  ")' 'bla.rstrip()'
1000000 loops, best of 5: 245 nsec per loop
./python -m timeit -s 'bla = bytearray(b"  foo  ")' 'bla.strip()'
1000000 loops, best of 5: 260 nsec per loop

Using my patch:

./python -m timeit -s 'bla = bytearray(b"  foo  ")' 'bla.lstrip()'
1000000 loops, best of 5: 235 nsec per loop
./python -m timeit -s 'bla = bytearray(b"  foo  ")' 'bla.rstrip()'
1000000 loops, best of 5: 235 nsec per loop
./python -m timeit -s 'bla = bytearray(b"  foo  ")' 'bla.strip()'
1000000 loops, best of 5: 239 nsec per loop


I have also updated the documentation, adding "whitespace" to the glossary and linking to it from many places in the documentation of standard types.

----------
nosy: +rompe

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


More information about the docs mailing list