From patchwork Thu Jan 21 12:44:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 10927 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 402E4BD808 for ; Thu, 21 Jan 2021 12:44:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B6D33681EE; Thu, 21 Jan 2021 13:44:41 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="E74Mz32C"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4D826681E6 for ; Thu, 21 Jan 2021 13:44:40 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id AD47F50E; Thu, 21 Jan 2021 13:44:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1611233080; bh=wHaolLLWY7852RSkVEoNwpeo/68pZIhmJylHFcWac8Y=; h=From:To:Cc:Subject:Date:From; b=E74Mz32CiT91u34HtvRRgm/p9J4jNM+XDBYAK31hngwnQkQtRYboVX57DdPEUKgkn LjWe8xkiqOqLvLWY4bbi9ssZweT6HnComCWEdrvjshot//jQo76q/pwXqZnySRBMRP I621NJbgPbd/qkjGH8mUQESsBpl1YAuSVUhijkO0= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Thu, 21 Jan 2021 14:44:17 +0200 Message-Id: <20210121124417.13629-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] utils: checkstyle.py: Fix "protected" members in Commit class X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The Commit class and subclasses were reworked in commit 4f5d17f3a4f5 ("utils: checkstyle.py: Make title and files properties of commit class") with the introduction of members of the base class that were meant to be protected (not used externally, but accessible by subclasses). They have been named with a '__' prefix for this purpose, which was a bad choice as Python effectively replaces a leading '__' with a literal '__classname__' prefix to make them private (https://docs.python.org/3/tutorial/classes.html#private-variables). The members accessed in the derived classes are thus different from the ones in the base class. Fix this by replacing the double underscore prefix with a single underscore, which is a "weak internal use indicator" (as specified in https://www.python.org/dev/peps/pep-0008/), closer to the protected access specifier of C++. Reported-by: Umang Jain Reported-by: Naushir Patuck Fixes: 4f5d17f3a4f5 ("utils: checkstyle.py: Make title and files properties of commit class") Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Tested-by: Naushir Patuck Reviewed-by: Naushir Patuck --- utils/checkstyle.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/utils/checkstyle.py b/utils/checkstyle.py index 0e9659e98518..fb9366f8095d 100755 --- a/utils/checkstyle.py +++ b/utils/checkstyle.py @@ -203,23 +203,23 @@ class CommitFile: class Commit: def __init__(self, commit): self.commit = commit - self.__parse() + self._parse() - def __parse(self): + def _parse(self): # Get the commit title and list of files. ret = subprocess.run(['git', 'show', '--pretty=oneline', '--name-status', self.commit], stdout=subprocess.PIPE).stdout.decode('utf-8') files = ret.splitlines() - self.__files = [CommitFile(f) for f in files[1:]] - self.__title = files[0] + self._files = [CommitFile(f) for f in files[1:]] + self._title = files[0] def files(self, filter='AM'): - return [f.filename for f in self.__files if f.status in filter] + return [f.filename for f in self._files if f.status in filter] @property def title(self): - return self.__title + return self._title def get_diff(self, top_level, filename): diff = subprocess.run(['git', 'diff', '%s~..%s' % (self.commit, self.commit), @@ -236,11 +236,11 @@ class StagedChanges(Commit): def __init__(self): Commit.__init__(self, '') - def __parse(self): + def _parse(self): ret = subprocess.run(['git', 'diff', '--staged', '--name-status'], stdout=subprocess.PIPE).stdout.decode('utf-8') - self.__title = "Staged changes" - self.__files = [CommitFile(f) for f in ret.splitlines()] + self._title = "Staged changes" + self._files = [CommitFile(f) for f in ret.splitlines()] def get_diff(self, top_level, filename): diff = subprocess.run(['git', 'diff', '--staged', '--', @@ -253,15 +253,15 @@ class Amendment(StagedChanges): def __init__(self): StagedChanges.__init__(self) - def __parse(self): + def _parse(self): # Create a title using HEAD commit ret = subprocess.run(['git', 'show', '--pretty=oneline', '--no-patch'], stdout=subprocess.PIPE).stdout.decode('utf-8') - self.__title = 'Amendment of ' + ret.strip() + self._title = 'Amendment of ' + ret.strip() # Extract the list of modified files ret = subprocess.run(['git', 'diff', '--staged', '--name-status', 'HEAD~'], stdout=subprocess.PIPE).stdout.decode('utf-8') - self.__files = [CommitFile(f) for f in ret.splitlines()] + self._files = [CommitFile(f) for f in ret.splitlines()] def get_diff(self, top_level, filename): diff = subprocess.run(['git', 'diff', '--staged', 'HEAD~', '--',