From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.gentoo.org (woodpecker.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) by sourceware.org (Postfix) with ESMTP id 0AF1B3858419 for ; Fri, 4 Nov 2022 15:13:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0AF1B3858419 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gentoo.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gentoo.org Received: by smtp.gentoo.org (Postfix, from userid 559) id 8D973341459; Fri, 4 Nov 2022 15:13:22 +0000 (UTC) Date: Fri, 4 Nov 2022 22:13:20 +0700 From: Mike Frysinger To: Jon Turney Cc: "newlib@sourceware.org" Subject: Re: [PATCH] makedocbook: Fix false report of unhandled texinfo command Message-ID: Mail-Followup-To: Jon Turney , "newlib@sourceware.org" References: <20221031095914.2277-1-jon.turney@dronecode.org.uk> <9b242eca-08ba-cc4f-fc2c-b8ad72992c37@dronecode.org.uk> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="p/LH2cR6+fefj23F" Content-Disposition: inline In-Reply-To: <9b242eca-08ba-cc4f-fc2c-b8ad72992c37@dronecode.org.uk> X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --p/LH2cR6+fefj23F Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 04 Nov 2022 13:50, Jon Turney wrote: > On 31/10/2022 12:28, Mike Frysinger wrote: > > On 31 Oct 2022 09:59, Jon Turney wrote: > >> + if match: > >> + print("texinfo command '%s' remains in output" % match.group(= ), file=3Dsys.stderr) > >=20 > > this is a little dangerous in general as match.group() could return a t= uple, > > and this would fail. if you want to use %, you should force a tuple. > > print("..." % (match.group(),), ...) >=20 > I must be missing something here, because I'm not sure in what sense=20 > 'could' is being used. I think match.group() is defined to be the same=20 > as match.group(0), which always returns a single string. (I guess this=20 > could be written explicitly). you are correct that match.group() is match.group(0) which guarantees to return a string. when i wrote this, i didn't have access to the python manual, so i checked against help() in the python repl. the docs there are much more terse and don't include the situations as to when a str or a tuple would be returned. > So the danger pointed out seems to be that if parts of the code were=20 > changed, without making other necessary changes, it would be wrong. But= =20 > I'm not sure the suggested change just to avoid that future possibility= =20 > makes things better or clearer. i've been bitten by refactors breaking % usage that lacks test coverage (which, practically speaking, i think you could say most of the python code here lacks unittests, especially in error code paths), so i have an allergy to code that uses % without guaranteeing somehow that a tuple is being passed like this code is doing now. i grok that `% foo` vs `% (foo,)` looks a bit funky when you aren't used to it, but i think this is more of a muscle memory thing -- this is the only way to write a single element tuple. i would have suggested using a f-string, but i don't know what versions of python you want to support as f-strings require Python 3.6+. of course if you really want to use % with a single element, i think it's wrong, but i'm not going to make a continued stink about it :p. > >> + exit(1) > >=20 > > scripts should never use exit(), only sys.exit(). although i see the c= urrent > > script gets this wrong in a lot of places. > >=20 > > also you can simplify this -- sys.exit accepts a string that it'll prin= t to > > stderr and then exit non-zero. > > sys.exit(".....") >=20 > Yes, this is one of the first things I wrote in python, and=20 > unfortunately, it shows. i wrote python like a C programmer for quite a long time, and it took a while to reform my brain for python idioms -mike --p/LH2cR6+fefj23F Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEuQK1JxMl+JKsJRrUQWM7n+g39YEFAmNlLBAACgkQQWM7n+g3 9YHD/A//ebXmWHVuJk3Sx+p8fX0Kyu2jh2vUuoLWSoszdoX8S9qa6I3ZQP2ByGuF apQrR7OC0pEM6V86pdf0g4B/zAPtQtxuvpl/95kSfseBCpsiB+NdBVsvbL+Vsr71 hdN1E5l+1hLoY152nwpu03p5PLhCJyRCw5USsL6ZAFRKJNMhSb9xKbTr9eQor8a3 V0VOg87NGuQ1yrG1VpGVDrWY243CPwBdYVw0hCuFQZOp+9/m4YidU8lCn/ga6hpw viRBvkXumTvgc8sAKIEJwr7DA6pTp9fRZnW8i7E5M3uAED3ctv0so5Qt2Uy9rzqG Ch/gP0l/3NlbhyuWGjjbsNLTd415ncvtdBFcRNR95XFgzu5b+YcjB59v1DTflRYu rOAX7872fmDGgjqD0st5U1QZL5vMK1Py/lSRvlxJhq0ZJVYzQxecbxQDvv6ws700 ksx7f4G2kNxjmUvkvDP7l8FYOP7giuGAAeqELq183ch+hcjGJo0BELlwIIqoCA10 MxOPoSY8NiHzx/254orAy8gfBOsXiy8RZOOWataEBC3fy7jvVoJshlKsO9GMuWJM grdLWnlAjEdHdZXS7haO63k9FYTqNrNtTbMGOAnxaaY4PCkx9O1vDfR5udUEUTyE rKC/DvWJoWxS76YeMh7XvI4hJu1F5wo1J8WqnVjTnjbxozBl2jI= =d0yS -----END PGP SIGNATURE----- --p/LH2cR6+fefj23F--