Embedded LLL code in python doesn't always play nice with linting rules. This seems to be a tug-of-war between:
There's not happy path that gets us both so, maybe there's a third option.
A functional utility for building LLL code in a way the preserves readability with respect to both LLL semantics and python semantics. Here's an example of the idea.
# as LLL
LLL = ["add", 1, 2]
# using builder
LLL = LLLBuilder.add(1, 2).generate()
A more complex example with some nesting:
# as LLL
LLL = ['sload', ['add', '_pos', ['mload', MemoryPositions.FREE_LOOP_INDEX]]]
# using builder
b = LLLBuilder
LLL = b.sload(
b.add('_pos', b.mload(MemoryPositions.FREE_LOOP_INDEX))
)
Everything above is just off the top of my head, but it is meant to demonstrate an API that allows us to generate LLL code in a manner that preserves easy readability of what the LLL code does while complying with python linting standards.
You could also leave out the state-hiding object and do a pure DSL, e.g.
def add(a, b) :
return LLLnode.from_list(['add', a, b])
FWIW, I did try generating LLL this way once and, although for small expressions it initially looked cleaner, I felt it was actually less easy to read than the string-based approach because the syntax highlighting applied to strings actually made the LLL stand out more. Also it was not consistent with the rest of the codebase so I just gave up. I'm not sure what the net effect of converting the entire codebase to this style would be.
Hmm I have to agree with @charles-cooper converting all the code at this point would seem like a ton of work, with zero gain except making a single linter rule happy. It has occured to me in the past that we could use tuples instead, this would solve the linting problem, but then we loose the mutability of building up lists - which actually proves useful, being able to .append() & a += [].
Another positive thing about the DSL approach is that once we have type checking in place we get some added type safety guarantees for LLL statements.
Most helpful comment
Another positive thing about the DSL approach is that once we have type checking in place we get some added type safety guarantees for LLL statements.