GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — parser: fix dotted decorator names by drew-512 · Pull Request #265 · go-python/gpython

Conversation

@drew-512

@drew-512 drew-512 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

A decorator with a dotted name was parsed into a single Name whose Id is the whole dotted string, so @decorators.author('Cleese') fails at runtime with NameError: name 'decorators.author' is not defined.

CPython 3.4 (ast_for_decorator / ast_for_dotted_name in Python/ast.c) builds Name(a) plus one Attribute(..., Load) per further component, all positioned at the start of the dotted name, and wraps that in a Call when there are arguments. The decorator rule now builds the same Name / Attribute chain through a small dottedName helper. Plain decorators also get the name's position instead of the @ (col 1 for @foo), as in CPython.

The helper is in parser.go rather than the grammar.y prologue so grammar.y keeps its line numbers: the regenerated y.go changes by one line and y.output not at all.

Tests:

  • vm/tests/decorators.py: enabled test_dotted and test_eval_order from CPython's test_decorators.py (both were commented out), and the nullval.attr case now expects AttributeError, as in CPython. All three fail on main with NameError.
  • parser: added dotted decorator cases to make_grammar_test.py and grammar_data_test.go (on a function, with call args, stacked on a class, and @a. staying a SyntaxError). No python3.4 here, so the new rows were written by hand in the generator's output format and cross-checked against CPython's ast.
  • go test -race ./... passes on Go 1.18, 1.19 and 1.27.

Fixes #264.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@drew-512
parser: fix dotted decorator names
91f651c
A decorator with a dotted name, e.g. a.b.c(x), was parsed into a
single Name whose Id was the whole string "a.b.c", so it failed at
runtime with NameError: name 'a.b.c' is not defined.

Build the decorator expression as CPython 3.4 does in
ast_for_dotted_name: a Name for the first component and one
Attribute (Load) per further component, all at the start of the
dotted name, wrapped in a Call when arguments are given. Plain
decorators now also carry the name's position rather than the '@',
as in CPython.

The new dottedName helper lives in parser.go so that grammar.y keeps
its line numbers: the regenerated y.go changes by one line and
y.output does not change.

Enable test_dotted and test_eval_order in vm/tests/decorators.py and
expect AttributeError for the nullval.attr decorator, as in CPython's
test_decorators.py. Add dotted decorator cases to the parser tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

parser: dotted decorator names raise NameError

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@drew-512
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.