bpo-15248: Emit a compiler warning when missed a comma before tuple or list. by serhiy-storchaka · Pull Request #11757 · python/cpython

@serhiy-storchaka

SylvainDe

Choose a reason for hiding this comment

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

This looks very cool!

As an additional comment/question: would it make sense to move the logic generating the type description from the expr_ty into a function on its own to limit duplication ? I gave it a try at https://pastebin.com/XLZ2B7Cq (not tested whatsoever).

@serhiy-storchaka

SylvainDe

Choose a reason for hiding this comment

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

I like this!

@serhiy-storchaka

gvanrossum

Choose a reason for hiding this comment

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

Love this! Just some suggestions on the error messages.

case JoinedStr_kind:
case FormattedValue_kind:
return compiler_warn(c, "'%.200s' object is not callable, "
"perhaps missed a comma?",

Choose a reason for hiding this comment

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

“perhaps you missed a comma?”

Also use “;” instead of “,” on the previous line.

case GeneratorExp_kind:
case Lambda_kind:
return compiler_warn(c, "'%.200s' object is not subscriptable, "
"perhaps missed a comma?",

Choose a reason for hiding this comment

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

Ditto.

@serhiy-storchaka

@serhiy-storchaka

@serhiy-storchaka

Thank you @SylvainDe! I also thought about this type of simplification, but was hesitant. I initially implemented this idea independently, but then I seen your nice variant and borrowed it.