[proxy] web.archive.org← back | site home | direct (HTTPS) ↗ | proxy home | ◑ dark◐ light
/ cpython Public

Conversation

Copy link
Member

serhiy-storchaka commented Mar 17, 2020

Copy link
Member

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

Copy link
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.

Co-Authored-By: Batuhan Taşkaya <47358913+isidentical@users.noreply.github.com>
case AugLoad:
case AugStore:
break;
default:
Copy link
Member

pablogsal Mar 17, 2020

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
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
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!

Copy link
Member

pablogsal left a comment

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 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
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 :)

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)
Copy link
Member

pablogsal Mar 17, 2020

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