scott-griffiths / bitstring

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

Add `return self` to the end of mutating methods #282

Closed ajahraus closed 1 year ago

ajahraus commented 1 year ago

By adding return self at the end of mutating operations, such as bytealign(), we have the option of writing

def some_function(args):
    return BitStream(f"uint8={args}").bytealign() # or whatever

But, because bytealign() returns nothing, we have to save to an intermediate variable

def some_function(args):
    stream = BitStream(f"uint8={args}") # or whatever
    stream.bytealign()
    return stream
ajahraus commented 1 year ago

My bad, I misinterpreted what the bytealign() method did, it only affects the pos field in a BitSteam or ConstBitStream when reading, it has nothing to do with creation.