From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by sourceware.org (Postfix) with ESMTPS id 75C6A385702F for ; Tue, 25 Oct 2022 13:04:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 75C6A385702F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-pg1-x535.google.com with SMTP id s196so11414928pgs.3 for ; Tue, 25 Oct 2022 06:04:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=mIObw9v/ITRnj4uniG/CDf1q8yPbZXX6L+ZszpX8uZ0=; b=G5Sq9RxB0YW6lu8GLEeC30B/pXsUGc48P9oqN+eAV2Z3nlo6+7Tm73VzNaOvqangZk sBlUgpuqzvFoVN7GGt7hwpeY4ZCSpkS/UuV5mM7sz6JrjcunzEwnEKKgqdlFCmROK74k o5lzsAWTIe7v/VQPmnfoIYzfIIzSOCZSWntGMynX8i6L8NablNaWV1NWCvEHcX9uxp0z SqLN/Om1WLMldmVkCE/UZWBN5NjmUB1GA/cbHyajMZav9Ybhm9ADzqWWcBJufPGkHKdF EH9/Afu+71sJnCMACbL59vh2Kbds6Ir6dKeBlX6oUvj9Wn0rvaIeslWlFnrUEBQMZ0Fy 3R5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=mIObw9v/ITRnj4uniG/CDf1q8yPbZXX6L+ZszpX8uZ0=; b=hgCbDrLzkOrv+nEFvApC2bYxnLVMhFjXLa2G6D1KL5CL3Ie6+UJOB+zMApIwdEFRzD AX9yYw27GvR0SS4A2zcsZxFOpB3jMChqatNralG8GGUUZwZAj53KzPjesK3F3OojtelI 5K+0vvml8GA1CcLMMgX9XMFYk7FykBUT6wz+WmDD0VGXMAlQd1vGRN1D49bO8HEXrR4t DBfUOsttKvC6C5FQsGRDr3J3ww15DxGic4Pe5P5kI16ypFw4L8dqizsUhJI4AgB0ssJX wgKV5mJo2/0+t+6+EdshGu0oSN6HQO3pRqGTy21J+B5xDyBh4Q6MGApi37s/ckbQnijD 2kzQ== X-Gm-Message-State: ACrzQf0sxuh1zY4FjI4lQiWyGkAHWLyDUtgT5hyG0mHlzZ46Uw/cbDzX jiyKRsjZ0/o/YDwtc9XDEQBA5UjtO8EirvE= X-Google-Smtp-Source: AMsMyM4ZfE9Yru1Tc6BO25Z/Qtz9kaKwo/M0uf4eeqnLnSqMk8+k310SJFyTqkjZVpsTU/RpQa9lfA== X-Received: by 2002:a63:235c:0:b0:459:5fef:88ab with SMTP id u28-20020a63235c000000b004595fef88abmr33170796pgm.312.1666703088490; Tue, 25 Oct 2022 06:04:48 -0700 (PDT) Received: from takamaka.gnat.com ([184.69.131.86]) by smtp.gmail.com with ESMTPSA id b78-20020a621b51000000b0056b4c5dde61sm1388415pfb.98.2022.10.25.06.04.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Oct 2022 06:04:44 -0700 (PDT) Received: by takamaka.gnat.com (Postfix, from userid 1000) id D0CE584042; Tue, 25 Oct 2022 09:04:39 -0400 (EDT) Date: Tue, 25 Oct 2022 09:04:39 -0400 From: Joel Brobecker To: gdb-patches@sourceware.org Cc: Joel Brobecker Subject: Re: [PATCH] gdb: copyright: make file header scan a bit more pythonic Message-ID: References: <20220101181509.25740-1-vapier@gentoo.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi Mike, On Mon, Oct 24, 2022 at 01:07:17AM +0545, Mike Frysinger via Gdb-patches wrote: > ping ... > -mike > > On 01 Jan 2022 13:15, Mike Frysinger via Gdb-patches wrote: > > Should be functionally the same, but uses more pythonic idioms to get > > fewer lines of code, and to make sure to not leak open file handles. Sorry about the delay in reviewing. The patch is approved and you can push it. Thanks for the patch. > > --- > > gdb/copyright.py | 15 ++++++--------- > > 1 file changed, 6 insertions(+), 9 deletions(-) > > > > diff --git a/gdb/copyright.py b/gdb/copyright.py > > index a78f7f2aa9b0..918d2e473d49 100755 > > --- a/gdb/copyright.py > > +++ b/gdb/copyright.py > > @@ -148,15 +148,12 @@ def may_have_copyright_notice(filename): > > # so just open the file as a byte stream. We only need to search > > # for a pattern that should be the same regardless of encoding, > > # so that should be good enough. > > - fd = open(filename, "rb") > > - > > - lineno = 1 > > - for line in fd: > > - if b"Copyright" in line: > > - return True > > - lineno += 1 > > - if lineno > 50: > > - return False > > + with open(filename, "rb") as fd: > > + for lineno, line in enumerate(fd, start=1): > > + if b"Copyright" in line: > > + return True > > + if lineno > 50: > > + break > > return False > > > > > > -- > > 2.33.0 > > -- Joel