Skip to content

LazyStruct and LazySequence don't use kwargs #365

@movermeyer

Description

@movermeyer

When using the Python 3.6+ keyword argument syntax to build constructs, building lazy constructs fails.

Example Code:

from construct import Struct, LazyStruct, Byte

MY_STRUCT_NON_KW = Struct(
    "a" / Byte,
    "b" / Byte,
    "c" / Byte,
    "d" / Byte,
)

MY_LAZY_STRUCT_NON_KW = LazyStruct(
    "a" / Byte,
    "b" / Byte,
    "c" / Byte,
    "d" / Byte,
)

MY_STRUCT = Struct(a=Byte, b=Byte, c=Byte, d=Byte)
MY_LAZY_STRUCT = LazyStruct(a=Byte, b=Byte, c=Byte, d=Byte)

print("MY_STRUCT_NON_KW:", MY_STRUCT_NON_KW.parse(b'\x00\x00\x00\x00'))
print("MY_LAZY_STRUCT_NON_KW:", MY_LAZY_STRUCT_NON_KW.parse(b'\x00\x00\x00\x00'))
print("MY_STRUCT:", MY_STRUCT.parse(b'\x00\x00\x00\x00'))
print("MY_LAZY_STRUCT:", MY_LAZY_STRUCT.parse(b'\x00\x00\x00\x00'))

gives:

MY_STRUCT_NON_KW: Container:
    a = 0
    b = 0
    c = 0
    d = 0
MY_LAZY_STRUCT_NON_KW: <LazyContainer: 4 possible items, 0 cached>
MY_STRUCT: Container:
    a = 0
    b = 0
    c = 0
    d = 0
MY_LAZY_STRUCT: <LazyContainer: 0 possible items, 0 cached>

I would have expected the lazy versions to produce the same values as the non-lazy versions.
Especially since the docs say they are equivalent and take in kwargs:

construct.LazyStruct(*subcons, **kw):
Equivalent to Struct construct

This is a result of LazyStruct and LazySequence not using their kw parameters at all.

Credits: Discovered with help from pylint

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions