[New-bugs-announce] [issue46167] Parse assert (x == y, "Descriptive text") as statement params instead of a tuple

Gregory P. Smith report at bugs.python.org
Thu Dec 23 14:58:53 EST 2021


New submission from Gregory P. Smith <greg at krypto.org>:

Now that we have a shiny new parser, can we finally get rid of this language wart:

assert thing, description  # works as intended

assert (thing, description)  # always True as non-empty tuples are Truthy

This most often happens when extending thing or description beyond a single line on assert statements as () are the natural way to do that and as it is with assert being a statement, knowing specifically where to place the ()s to not fall into the pit of snakes of unintentionally nerfing your assertion to be an always true tuple is hard for human authors.

This would obsolete the pylint error about tuple assertion and enable more natural assert use.

py.test framework users would presumably rejoice as well.


This parsing change would need a PEP.  I fail to see any obvious downsides though.

----------
components: Parser
messages: 409101
nosy: gregory.p.smith, lys.nikolaou, pablogsal
priority: normal
severity: normal
status: open
title: Parse assert (x == y, "Descriptive text") as statement params instead of a tuple
versions: Python 3.11

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46167>
_______________________________________


More information about the New-bugs-announce mailing list