Skip to content

fix(schema): a non-final Schema subclass built after its parent leaks internal keys from to_dict() #1498

Closed

Description

@JarryShaw

Describe the bug
#1490 for Schema: once a non-final Schema parent has been instantiated, its non-final children are never finalised. Their to_dict() then leaks internal names.

Reproduction

from pcapkit.protocols.schema.schema import Schema
from pcapkit.corekit.fields.numbers import UInt8Field
class P(Schema):
    a: 'int' = UInt8Field()
class C(P):
    b: 'int' = UInt8Field()
P.unpack(b'\x01')
list(C.unpack(b'\x01\x02').to_dict())   # ['__map__', '__map_reverse__', '__buffer__', '__updated__', 'a', 'b']

len() and iteration are correct (2, ['a', 'b']). C.__dict__ has no __finalised__, and C.__init__ is P.__init__.

Expected behavior
to_dict() returns ['a', 'b'], whichever class was built first.

System information
Linux, CPython 3.14.7, main at 00aa1fc90.

Additional context

Activity

  1. added
    fixPull requests that fix a defect (fix: subject prefix)
    pendingAccepted and unstarted - nobody is on it and nothing blocks it
    wipWork in flight - a covering PR is open or an agent is actively on it
    and removed
    pendingAccepted and unstarted - nobody is on it and nothing blocks it
    on Oct 9, 2026
  2. removed
    wipWork in flight - a covering PR is open or an agent is actively on it
    on Oct 9, 2026
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

    fixPull requests that fix a defect (fix: subject prefix)

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions