Skip to content

schema_final's generated typed __init__ is dead code, so Schema.__post_init__ never runs #422

Description

@JarryShaw

pcapkit/protocols/schema/schema.py:77 guards the generated typed __init__
with a test that is always false, because Schema.__init__ is
Schema.__update__:

Schema.__init__ is Schema.__update__: True

So the typed __init__ that schema_final generates is never installed, and in
consequence __post_init__ is never called on any schema.

Why it matters

Two things are quietly not happening:

  • Any __post_init__ a schema defines is inert. Anyone adding one would
    reasonably expect it to run, and it will not — silently, with no error.
  • The generated signature is what a type checker and an IDE would use to check
    Schema(...) construction, so the checking is weaker than it looks.

Whether the fix is to correct the guard or to delete the generation depends on
whether __post_init__ is wanted at all — worth deciding rather than assuming,
since nothing currently relies on it and correcting the guard would start
running hooks that have never run.

Found while profiling for #420 (not a performance issue — noticed in passing).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssues reporting a defect (set by the bug report template; a default, not an assessment)

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions