Skip to content

fix(scripts): make cocotb_ref_model importable again - #1589

Merged
gHashTag merged 6 commits into
masterfrom
fix/cocotb-forward-reference
Aug 1, 2026
Merged

fix(scripts): make cocotb_ref_model importable again#1589
gHashTag merged 6 commits into
masterfrom
fix/cocotb-forward-reference

Conversation

@gHashTag

@gHashTag gHashTag commented Aug 1, 2026

Copy link
Copy Markdown
Owner

scripts/cocotb_ref_model.py fails at import:

NameError: name 'EvalContext' is not defined

EvalContext is used as a parameter annotation at lines 174 and 215; the class is defined at line 402. Python evaluates annotations at function-definition time unless the module opts out, so the forward reference raises before argparse runs and the tool cannot be invoked at all.

from __future__ import annotations defers annotation evaluation. After it the module loads and reaches its own parser:

usage: cocotb_ref_model.py [-h] --ast-json AST_JSON --verilog VERILOG
                           --top-module TOP_MODULE [--use-cocotb] [--verbose]

Placement matters. A __future__ import may be preceded only by the module docstring, comments and blank lines. Putting it between the shebang and the docstring also makes the module load — but silently demotes the docstring to an ordinary string expression, leaving __doc__ as None. It goes after the docstring here, and ast.get_docstring confirms the docstring survives.

Found by extending the side-effect sweep of #1581 to the EXEC bucket — the last 12 scripts in the repository that had never been executed. No workflow references this file, which is why the breakage went unnoticed.

Closes #1592

The module fails at import:

  NameError: name 'EvalContext' is not defined

EvalContext is annotated on function parameters at lines 174 and 215 but the class
is defined at line 402. Python evaluates annotations at function-definition time
unless the module opts out, so the forward reference raises before argparse is
reached and the tool cannot run at all.

Adding `from __future__ import annotations` defers annotation evaluation and the
module loads. Afterwards it reaches its own argument parser and reports what it
needs:

  usage: cocotb_ref_model.py [-h] --ast-json AST_JSON --verilog VERILOG
                             --top-module TOP_MODULE [--use-cocotb] [--verbose]

Placement matters and is easy to get wrong: a __future__ import may be preceded
only by the module docstring, comments and blank lines. Inserting it between the
shebang and the docstring also makes the module load, but silently demotes the
docstring to an ordinary string expression and leaves __doc__ as None. It is
inserted after the docstring here, and ast.get_docstring confirms the docstring
survives.

Found by extending the pass-57/58 side-effect sweep to the EXEC bucket -- the last
12 scripts in the repository that had never been executed. No workflow references
this file, which is why the breakage went unnoticed.
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

📓 NotebookLM Notebook linked to this PR

This notebook contains session context, decisions, and artifacts for this work.

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

PR Dashboard

Generated at: 2026-08-01 05:44:36 UTC

Summary

Status Count
Total Open PRs 50
PRs with Failing Checks 40
PRs with All Checks Green 10
READY 1
FAILING 40
PENDING 0

Seal Status

  • ⚠️ STALE -- sha256(compiler.rs)=d6b51a3bcc20 != manifest seal=87e5cbd3ad94.
    The committed NMSE numbers were certified against an older compiler.rs.
    Run scripts/reseal-check.sh locally for the two-step reseal command (advisory; not a merge gate).

now-sync-gate requires every PR to master to update docs/NOW.md.
This PR predates my knowing that; the entry describes what it
lands and states its honesty limits, in the file's existing shape.
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

📓 NotebookLM Notebook linked to this PR

This notebook contains session context, decisions, and artifacts for this work.

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

PR Dashboard

Generated at: 2026-08-01 07:44:48 UTC

Summary

Status Count
Total Open PRs 50
PRs with Failing Checks 38
PRs with All Checks Green 12
READY 1
FAILING 38
PENDING 0

Seal Status

  • ⚠️ STALE -- sha256(compiler.rs)=d6b51a3bcc20 != manifest seal=87e5cbd3ad94.
    The committed NMSE numbers were certified against an older compiler.rs.
    Run scripts/reseal-check.sh locally for the two-step reseal command (advisory; not a merge gate).

@gHashTag
gHashTag enabled auto-merge (squash) August 1, 2026 07:46
Five branches each added an entry at the top of docs/NOW.md, so the
first merge conflicted with the other four. Resolved losslessly: this
branch's entry sits on top of master's file as it now stands.
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

📓 NotebookLM Notebook linked to this PR

This notebook contains session context, decisions, and artifacts for this work.

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

PR Dashboard

Generated at: 2026-08-01 07:48:14 UTC

Summary

Status Count
Total Open PRs 50
PRs with Failing Checks 36
PRs with All Checks Green 14
READY 1
FAILING 36
PENDING 0

Seal Status

  • ⚠️ STALE -- sha256(compiler.rs)=d6b51a3bcc20 != manifest seal=87e5cbd3ad94.
    The committed NMSE numbers were certified against an older compiler.rs.
    Run scripts/reseal-check.sh locally for the two-step reseal command (advisory; not a merge gate).

Every PR here must touch docs/NOW.md and every entry goes at the top, so
each merge conflicts whatever is still open. Resolved losslessly: this
branch's entry sits on top of master's file as it now stands.
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

PR Dashboard

Generated at: 2026-08-01 08:00:49 UTC

Summary

Status Count
Total Open PRs 50
PRs with Failing Checks 37
PRs with All Checks Green 13
READY 1
FAILING 37
PENDING 0

Seal Status

  • ⚠️ STALE -- sha256(compiler.rs)=d6b51a3bcc20 != manifest seal=87e5cbd3ad94.
    The committed NMSE numbers were certified against an older compiler.rs.
    Run scripts/reseal-check.sh locally for the two-step reseal command (advisory; not a merge gate).

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

📓 NotebookLM Notebook linked to this PR

This notebook contains session context, decisions, and artifacts for this work.

Every PR here must touch docs/NOW.md and every entry goes at the top,
so each merge conflicts whatever is still open. Resolved losslessly.
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

PR Dashboard

Generated at: 2026-08-01 08:02:12 UTC

Summary

Status Count
Total Open PRs 50
PRs with Failing Checks 39
PRs with All Checks Green 11
READY 1
FAILING 39
PENDING 0

Seal Status

  • ⚠️ STALE -- sha256(compiler.rs)=d6b51a3bcc20 != manifest seal=87e5cbd3ad94.
    The committed NMSE numbers were certified against an older compiler.rs.
    Run scripts/reseal-check.sh locally for the two-step reseal command (advisory; not a merge gate).

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

📓 NotebookLM Notebook linked to this PR

This notebook contains session context, decisions, and artifacts for this work.

Every PR here must touch docs/NOW.md and every entry goes at the
top, so each merge conflicts whatever is still open.
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

📓 NotebookLM Notebook linked to this PR

This notebook contains session context, decisions, and artifacts for this work.

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

PR Dashboard

Generated at: 2026-08-01 08:05:29 UTC

Summary

Status Count
Total Open PRs 50
PRs with Failing Checks 38
PRs with All Checks Green 12
READY 1
FAILING 38
PENDING 0

Seal Status

  • ⚠️ STALE -- sha256(compiler.rs)=d6b51a3bcc20 != manifest seal=87e5cbd3ad94.
    The committed NMSE numbers were certified against an older compiler.rs.
    Run scripts/reseal-check.sh locally for the two-step reseal command (advisory; not a merge gate).

@gHashTag
gHashTag merged commit cb8bcfb into master Aug 1, 2026
20 of 21 checks passed
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.

cocotb_ref_model.py raises NameError at import and cannot be run

1 participant