scott-griffiths / bitstring

A Python module to help you manage your bits
https://bitstring.readthedocs.io/en/stable/index.html
MIT License
401 stars 68 forks source link

Invalid escape sequence in top-level docstring #207

Closed kriek closed 3 years ago

kriek commented 4 years ago

Hi,

the top-level docstring in bitstring v3.1.6 should be raw because it uses backslashes in its ASCII art diagram:

                      Bits (base class)
                     /    \
 + mutating methods /      \ + streaming methods
                   /        \
              BitArray   ConstBitStream
                   \        /
                    \      /
                     \    /
                    BitStream

Running pylint via pytest-pylint on code using bitstring (python 3.8 if that matters) results in a SyntaxError:

../../.envs/scientific/lib/python3.8/site-packages/_pytest/python.py:513: in _importtestmodule
    mod = self.fspath.pyimport(ensuresyspath=importmode)
../../.envs/scientific/lib/python3.8/site-packages/py/_path/local.py:701: in pyimport
    __import__(modname)
<frozen importlib._bootstrap>:991: in _find_and_load
    ???
<frozen importlib._bootstrap>:975: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:671: in _load_unlocked
    ???
../../.envs/scientific/lib/python3.8/site-packages/_pytest/assertion/rewrite.py:152: in exec_module
    exec(co, module.__dict__)
test_codec.py:3: in <module>
    from bitstring import BitArray, CreationError
E     File "~/.envs/scientific/lib/python3.8/site-packages/bitstring.py", line 2
E       """
E       ^
E   SyntaxError: invalid escape sequence \

Making the docstring a raw one ("r" prefix) is fixing the issue.

By the way, nice job writing this library, it is my go to choice when dealing with serialization/deserialization protocols !

scott-griffiths commented 3 years ago

Tsk, now Python's criticising my ASCII art. That's a bit surprising as I'm sure the tests pass in Python 3.8 (though I tested with bitstring 3.1.7, but that shouldn't make a difference here). I'll try to reproduce the issue and get a fix in for the next release. Thanks.

kriek commented 3 years ago

Not everyone can appreciate the beauty of ASCII art :) pylint itself does not show the problem. But when it is called from pytest, pytest will collect warnings (and optionally turn them into errors). Steps to reproduce: