Skip to content

bpo-39988: Remove ast.AugLoad and ast.AugStore node classes.#19038

Merged
serhiy-storchaka merged 7 commits into
python:masterfrom
serhiy-storchaka:ast-augassign
Mar 17, 2020
Merged

bpo-39988: Remove ast.AugLoad and ast.AugStore node classes.#19038
serhiy-storchaka merged 7 commits into
python:masterfrom
serhiy-storchaka:ast-augassign

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Mar 17, 2020

Copy link
Copy Markdown
Member

@isidentical

Copy link
Copy Markdown
Member

@serhiy-storchaka can you remove the first commit, I think it is unrelated to this bug.

@serhiy-storchaka

Copy link
Copy Markdown
Member Author

This PR depends on #19037. After merging #19037 and synchronizing this PR with master the final diff will look cleaner. For now you can choose what commits you want to see in https://github.com/python/cpython/pull/19038/files.

Comment thread Doc/whatsnew/3.9.rst Outdated
Co-Authored-By: Batuhan Taşkaya <47358913+isidentical@users.noreply.github.com>
Comment thread Python/compile.c
case AugLoad:
case AugStore:
break;
default:

@pablogsal pablogsal Mar 17, 2020

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we keep the default just in case we receive some invalid value in the switch? (The same applies with the other ones). I may be missing the reason why you remove them, tough 🤔

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is impossible to get invalid value in ctx. compiler_nameop() is called either with a literal value or with e->v.Name.ctx, and it is validated before setting to e->v.Name.ctx.

It is more robust to not add the default because the compiler will warn if we add a new member to the expr_context_ty enum but do not have a corresponding case in a switch. If keep the default, the compiler would not catch this error at compile time.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, thanks for the explanation!

@pablogsal pablogsal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Thanks Serhiy, this is a great improvement!

Comment thread Python/compile.c
Comment on lines +5047 to +5049
VISIT(c, expr, e->v.Attribute.value);
ADDOP(c, DUP_TOP);
ADDOP_NAME(c, LOAD_ATTR, e->v.Attribute.attr, names);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I find this code much cleaner and straightforward :)

Comment thread Python/compile.c Outdated

d_bytecode = (a->a_offset - a->a_lineno_off) * sizeof(_Py_CODEUNIT);
d_lineno = i->i_lineno - a->a_lineno;
if (d_lineno == 0)

@pablogsal pablogsal Mar 17, 2020

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Pep 7 (Ignore if you want, I think this is also in the other PR)

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.

5 participants