Skip to content

fix(test): grouped keyword unions schema into objects of smaller size to allow CPython compilation - #3125

Open
carloscasellas wants to merge 1 commit into
glideapps:masterfrom
carloscasellas:agent/issue-3119
Open

fix(test): grouped keyword unions schema into objects of smaller size to allow CPython compilation#3125
carloscasellas wants to merge 1 commit into
glideapps:masterfrom
carloscasellas:agent/issue-3119

Conversation

@carloscasellas

Copy link
Copy Markdown

Description

Restructures the test/inputs/schema/keyword-unions.schema fixture (and the generator that produces it, test/keywords.py) so that its ~275 top-level union properties are split into 5 nested objN objects of at most 64 properties each, instead of one flat object with all 275 properties. Updates the keyword-unions.2.json sample to nest its value under obj1 to match the new shape, and removes the Python-specific skipSchema entry that previously excluded this fixture from the Python test matrix.

Related Issue

Fixes #3119

Motivation and Context

keyword-unions.schema generates one Python class per top-level object, with a positional-argument constructor call (from_dict) that takes one argument per property. With all 275 properties on a single flat object, quicktype generated a 276-argument constructor call, which exceeds CPython's hard limit of 255 arguments per call — the generated Python module fails to compile/import with a SyntaxError.

Because of this, the fixture was permanently skipped for Python (test/languages.ts), which meant there was no test coverage catching this class of bug: any real-world schema wide enough to trip the same 255-argument ceiling would silently produce broken, unusable Python from quicktype, with nothing in CI to catch it.

Grouping the schema's properties into smaller nested objects keeps the widest generated constructor call well under the 255-argument limit while still exercising every keyword/property the fixture is meant to cover, so the fixture can now run — and stay covered — for Python.

Previous Behaviour / Output

test/languages.ts explicitly skipped this schema for Python:

skipSchema: [
    "keyword-unions.schema", // Requires more than 255 arguments
],

Generating Python from the (unskipped) flat schema produced a 276-argument call site, e.g.:

return TopLevel(empty, purple_bool, complex, imaginery, abstract, alignas, ... # 276 args total

which raises SyntaxError: more than 255 arguments at import/call time — the generated code was never actually valid Python.

New Behaviour / Output

The schema now groups its properties into 5 nested objects (obj1..obj5) of up to 64 properties each. The generated Python's widest constructor call site is now 65 arguments (Obj1), well under the 255-argument ceiling:

return Obj1(empty, purple_bool, complex, imaginery, ... constructor, ... dummy)  # 65 args

test/languages.ts's skipSchema no longer excludes keyword-unions.schema for Python (skipSchema: []), so the fixture now runs as part of the normal Python test matrix.

How Has This Been Tested?

  • Regenerated the schema via test/keywords.py --unions and diffed it against the committed test/inputs/schema/keyword-unions.schema — byte-for-byte match, confirming the generator and the checked-in fixture are in sync.
  • Built quicktype (npm run build) and ran node dist/index.js --lang python --src-lang schema test/inputs/schema/keyword-unions.schema directly; confirmed the widest generated constructor call is 65 arguments (Obj1), and that python3 -m py_compile succeeds on the output.
  • Installed mypy locally (not present by default in this environment) and ran the actual fixture test end-to-end:
    FIXTURE=schema-python QUICKTEST=true npm run test:fixtures -- test/inputs/schema/keyword-unions.schema — passes, exercising both the .1.json ({}) and .2.json ({ "obj1": { "constructor": 123 } }) samples through the full generate → compile/typecheck → round-trip pipeline, not just a static check.
  • Verified keyword-unions.2.json's new nested shape ({ "obj1": { "constructor": 123 } }) is still valid against the schema, and that keyword-unions.1.json's {} remains valid since the schema has no required properties at any level.
  • Checked test/languages.ts for other languages referencing keyword-unions.schema: all other languages that skip it do so for unrelated, pre-existing reasons (naming collisions, memory limits, etc.) untouched by this change, so no other language's test configuration was affected.

Screenshots (if appropriate):

N/A — this is a test-fixture/schema change with no visual output.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: keyword-unions.schema is not valid for python testing

1 participant