On Tue, Oct 20, 2020 at 2:02 PM Chris Jerdonek <[email protected]> wrote:
> On Mon, Oct 19, 2020 at 3:11 PM Thomas Wouters <[email protected]> wrote: > >> PEP: 640 >> Title: Unused variable syntax >> Author: Thomas Wouters <[email protected]> >> > ... > >> In Python it is somewhat common to need to do an assignment without >> actually >> needing the result. Conventionally, people use either ``"_"`` or a name >> such >> as ``"unused"`` (or with ``"unused"`` as a prefix) for this. It's most >> common in *unpacking assignments*:: >> > > Many times I'm not using an assignment target, I still like to give a > descriptive name. The reason is that it lets me see what value I'm not > using. It helps to document and confirm my understanding of the value being > unpacked. It also lets you toggle easily between using and not using a > value if you're working on the code. > > To illustrate, I might do this-- > > scheme, _netloc, _path, params, query, fragment = urlparse(url) > > instead of this-- > > scheme, _, _, params, query, fragment = urlparse(url) > > So I'd prefer if the scheme would allow including a name (either by > prefixing or some other method), or at least not preclude such an extension > in the future. > It does not preclude it -- ?somename is not valid syntax, so it could be added later -- but please note that the pattern matching proposal also does not allow this. Using names instead of ? is still an option -- both in regular unpacking and in pattern matching -- it just does something subtly different. The reason for this PEP is that pattern matching will make '_' (but not any other names) have the behaviour suggested in this PEP, but *only* in pattern matching. > > --Chris > > > -- Thomas Wouters <[email protected]> Hi! I'm an email virus! Think twice before sending your email to help me spread!
_______________________________________________ Python-Dev mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/[email protected]/message/4AVMQ3ZW5IEMSR2WWWMDAAK6Y36CH4JD/ Code of Conduct: http://python.org/psf/codeofconduct/
