Skip to content

v0.7.10.10

Choose a tag to compare

@github-actions github-actions released this 30 Apr 03:02
· 4 commits to main since this release
v0.7.10.10
dce063b

v0.7.10.10 — Name decorators via codegen_decorators + codegen_apply_decorators

Date: 2026-04-30
Spec: notes/Spec/1500/1568_gocopy_v07110_decorators.md
Roadmap: notes/Spec/1500/1558_gocopy_v0710x_release_roadmap.md

v0.7.10.10 opens visitFuncBodyDef to bare-Name decorators —
@d, @d1\n@d2\n chains, and any compositional combination
with the existing default / kwonly / posonly / *args /
**kwargs surface. Decorator expressions richer than a single
Name (Attribute @module.dec, Call @dec(arg)) gate out and
fall through to the legacy visitClosureDef /
visitFunctionDef path.

The emit mirrors Python/codegen.c::codegen_function's
decorator brackets:

LOAD_NAME d           (decoLoc)        ← codegen_decorators
... default tuple, kwdefault dict (existing)
LOAD_CONST funcCode   (outerLoc)       ← codegen_function_body
MAKE_FUNCTION         (outerLoc)
SET_FUNCTION_ATTRIBUTE 2 / 1 (existing)
CALL 0                (decoLoc)        ← codegen_apply_decorators
STORE_NAME g          (outerLoc)       ← codegen_nameop Store

For N decorators, pushes are in source order
(d1, d2, ..., dN); CALL 0 emits are in reverse source
order (dN, dN-1, ..., d1), each carrying its own decorator's
loc — matches CPython's positions table exactly.

Spec 1558 §v0.7.10.10 originally bundled annotations and the
three-visitor collapse with decorators. Annotations in 3.14
require a deferred-eval scope (PEP 649,
codegen_setup_annotations_scope opens a separate code unit
gated by MAKE_FUNCTION_ANNOTATE) — substantial pipeline work
that splits off into a follow-up release. The visitor collapse
is similarly its own refactor.

Inner-code metadata change

co_firstlineno of the inner function code now equals
decorators[0].P.Line when decorators are present (matching
Python/codegen.c::codegen_function line 1421-1423). RESUME's
loc inside the inner code uses firstlineno, not the def line.
Linetable deltas inside the inner code key off the decorator
line, exactly as CPython's.

Added

  • tests/fixtures/funcbody/034_decorator_single.py —
    @d\ndef g(): return 1. Pins single decorator: LOAD_NAME +
    funcCode-MAKE_FUNCTION + CALL 0 + STORE_NAME, with inner
    co_firstlineno set to decorator's line.
  • tests/fixtures/funcbody/035_decorator_chain.py —
    @d1\n@d2\ndef g(): return 1. Pins decorator chain: two
    pushes in source order, two CALL 0 in reverse, distinct loc
    per CALL.

Changed

  • compiler/codegen/visit_funcbody_stmt.go — early gate now
    accepts non-empty DecoratorList provided every entry is a
    bare *ast.Name (col ≤ 255, name 1..15 chars, line ≥ 1).
    Returns annotation and TypeParams stay gated. Inner unit's
    firstlineno uses decorators[0].P.Line when decorated;
    resumeLoc follows. Two new emit blocks bracket the existing
    defaults / kwdefaults / MAKE_FUNCTION / SET_* sequence:
    decorator pushes (forward order) before defaults, and
    CALL 0 × N (reverse order) after SET_FUNCTION_ATTRIBUTE
    but before STORE_NAME. Both blocks use a per-decorator
    decoLoc(n) helper that spans (line, col, col+len(id)).
  • CHANGELOG.md — v0.7.10.10 entry added.

Tests

  • Oracle (bash tests/run.sh): 275/275 fixtures byte-identical
    (was 273/273).
  • Visitor parity (go test ./compiler/ -run TestVisitorParity):
    byte-identical=235 not-implemented=40 mismatched=0 errored=0
    (was 233/40/0/0).
  • All existing tests stay green.

Out of scope (deferred)

  • Annotations (param + return). PEP 649 deferred-eval scope
    required — landing in a follow-up release.
  • Visitor collapse — visitFuncBodyDef /
    visitClosureDef / visitFunctionDef will fold into a single
    codegenFunction once annotations land.
  • Attribute decorators (@module.dec). Need
    visitFuncExpr-style decorator expression visit, not just
    LOAD_NAME.
  • Call decorators (@dec(arg), e.g.
    @dataclass(slots=True)). Same as Attribute, plus argument
    visit + CALL N rather than CALL 0.