From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id P080FQ3fV2MefRAAWB0awg (envelope-from ) for ; Tue, 25 Oct 2022 09:05:17 -0400 Received: by simark.ca (Postfix, from userid 112) id 476951E112; Tue, 25 Oct 2022 09:05:17 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=AHmMswy/; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id EEEB71E0D5 for ; Tue, 25 Oct 2022 09:05:16 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4DB4C3857362 for ; Tue, 25 Oct 2022 13:05:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4DB4C3857362 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666703116; bh=mIObw9v/ITRnj4uniG/CDf1q8yPbZXX6L+ZszpX8uZ0=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=AHmMswy/7AvALFUaH0jLxnV8Dlmw08wLG2qNFiSLEWew4T/Wxn2DuKXYBVohtmYfE B2DvWApo1A1bdwPoZBi3AwxTpWyinCGM5/P3bXEP8W4NpNyI/yzv+Xa3PZCx5J3Yj5 JxHYUV3rnQxBaU5UpxvxOgYFbey6/y5xC5SyVRoQ= 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 Received: by mail-pg1-x535.google.com with SMTP id s196so11414928pgs.3 for ; Tue, 25 Oct 2022 06:04:49 -0700 (PDT) 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 To: gdb-patches@sourceware.org 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-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Joel Brobecker via Gdb-patches Reply-To: Joel Brobecker Cc: Joel Brobecker Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" 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