No description
Find a file
2020-12-12 14:08:57 +01:00
.vscode added stubs for py3compat.py 2020-12-10 21:57:31 +01:00
construct-stubs added stubs for StopIf 2020-12-12 14:08:57 +01:00
construct_typed put a prefix before every object of "typing", because there are a few duplications, e.g. Union and Optional. 2020-12-12 13:17:27 +01:00
tests put a prefix before every object of "typing", because there are a few duplications, e.g. Union and Optional. 2020-12-12 13:17:27 +01:00
.gitignore Initial Version 2020-12-09 21:26:16 +01:00
LICENSE Initial commit 2020-12-04 17:16:20 +01:00
README.md added README.md 2020-12-10 20:26:37 +01:00
setup.py added README.md 2020-12-10 20:26:37 +01:00

construct-typing

This project is an extension of the python package construct. This Repository consitst of two packages:

  • construct-stubs: Adding .pyi for the whole construct package (according to PEP 561 stub-only packages)
  • construct-typed: Adding the additional classes TypedStruct and TypedEnum that help with autocompletion in cooperation with the stubs.

Motivation

Examples

An example of the added TypedStruct class:

from construct import *
from construct_typed import *

class Image(TypedContainer):
    signature: Subcon(Const(b"BMP"))
    width: Subcon(Int8ub())
    height: Subcon(Int8ub())
    pixels: Subcon(Array(cs.this.width * cs.this.height, Byte()))

format = TypedStruct(Image)
obj = Image(width=3, height=2, pixels=[7, 8, 9, 11, 12, 13])
print(format.build(obj))
print(format.parse(b"BMP\x03\x02\x07\x08\t\x0b\x0c\r"))

An example of the added TypedEnum class: