From nobody Mon Feb 9 05:58:34 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E684281530 for ; Wed, 4 Feb 2026 14:51:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770216671; cv=none; b=arkTTDbhLgYrQkUHtUWT4zLY9LeZMAn3RS9/W24eK38fumHB/23ROVXzbWAyPakyWHJpg8v1f5eoxnfZughjXSuvRhgpV6C4mCgDl28vGARFOSq3uwc4DLNWKb5CsPqbVP4SaFX7rgLYlh58bQ1PX6iWaKAmnd3snx6OmDJmEgg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770216671; c=relaxed/simple; bh=9c4O8Mdm+ewS4xkU8uOqSlYRYgEjTA8B0nGZ//Zuabc=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Rzd6HJLgu/AoHhjeAPZOOVGbUt3sMQYzOUp9uEWWmyQzffAdIhCn4Vj9uwiWBxEXhmZSNKL+thRD107gwV5ItCU7wOf79UwpG19b2pYh7+7LAfGdq0TGnJ/YK5t1OnzrjgTWlm6Q1ev6VBhv54aOM/l9qUDFxm/qg7uT1cN2Sjk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=K/dw+TaO; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="K/dw+TaO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770216670; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8sJU2RJB3KUNxhCCTIsG7NiQCqE4cV2jotMaoDK+oRk=; b=K/dw+TaO11MePuTX6y5QnLY3WUv/bqdhaCrgJ4LFbUzW2hhdbA/TEf2HPLqQJrb2HTxzLD hDyTMSTL+EXDCG4O2yJGplKMaMTEqnr7/F6YeOkK7SuvMt1bVXVf8ekD0+FgbtVtd31jW1 BvMwV6/zjKmiU5TOLO7fvEhrKPShQoE= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-250-6akKEpkxPhusFHdnBJFHrw-1; Wed, 04 Feb 2026 09:51:06 -0500 X-MC-Unique: 6akKEpkxPhusFHdnBJFHrw-1 X-Mimecast-MFC-AGG-ID: 6akKEpkxPhusFHdnBJFHrw_1770216665 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7F8BC1956094; Wed, 4 Feb 2026 14:51:05 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.88.140]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C193A30001BC; Wed, 4 Feb 2026 14:51:02 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Gabriele Monaco , Nam Cao , Wander Lairson Costa , linux-trace-kernel@vger.kernel.org (open list:RUNTIME VERIFICATION (RV)), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 04/20] rv/rvgen: replace __len__() calls with len() Date: Wed, 4 Feb 2026 11:42:30 -0300 Message-ID: <20260204144914.104028-5-wander@redhat.com> In-Reply-To: <20260204144914.104028-1-wander@redhat.com> References: <20260204144914.104028-1-wander@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" Replace all direct calls to the __len__() dunder method with the idiomatic len() built-in function across the rvgen codebase. This change eliminates a Python anti-pattern where dunder methods are called directly instead of using their corresponding built-in functions. The changes affect nine instances across two files. In automata.py, the empty string check is further improved by using truthiness testing instead of explicit length comparison. In dot2c.py, all length checks in the get_minimun_type, __get_max_strlen_of_states, and get_aut_init_function methods now use the standard len() function. Additionally, spacing around keyword arguments has been corrected to follow PEP 8 guidelines. Direct calls to dunder methods like __len__() are discouraged in Python because they bypass the language's abstraction layer and reduce code readability. Using len() provides the same functionality while adhering to Python community standards and making the code more familiar to Python developers. Signed-off-by: Wander Lairson Costa Reviewed-by: Gabriele Monaco Reviewed-by: Nam Cao --- tools/verification/rvgen/rvgen/automata.py | 2 +- tools/verification/rvgen/rvgen/dot2c.py | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/verification/rvgen/rvgen/automata.py b/tools/verificatio= n/rvgen/rvgen/automata.py index bd8c04526be3a..07ae81e9a49fa 100644 --- a/tools/verification/rvgen/rvgen/automata.py +++ b/tools/verification/rvgen/rvgen/automata.py @@ -42,7 +42,7 @@ class Automata: raise AutomataError(f"not a dot file: {self.__dot_path}") =20 model_name =3D ntpath.splitext(basename)[0] - if model_name.__len__() =3D=3D 0: + if not model_name: raise AutomataError(f"not a dot file: {self.__dot_path}") =20 return model_name diff --git a/tools/verification/rvgen/rvgen/dot2c.py b/tools/verification/r= vgen/rvgen/dot2c.py index 6a2ad4fbf7824..b3a49779d4cc5 100644 --- a/tools/verification/rvgen/rvgen/dot2c.py +++ b/tools/verification/rvgen/rvgen/dot2c.py @@ -64,14 +64,14 @@ class Dot2c(Automata): def get_minimun_type(self) -> str: min_type =3D "unsigned char" =20 - if self.states.__len__() > 255: + if len(self.states) > 255: min_type =3D "unsigned short" =20 - if self.states.__len__() > 65535: + if len(self.states) > 65535: min_type =3D "unsigned int" =20 - if self.states.__len__() > 1000000: - raise AutomataError(f"Too many states: {self.states.__len__()}= ") + if len(self.states) > 1000000: + raise AutomataError(f"Too many states: {len(self.states)}") =20 return min_type =20 @@ -114,12 +114,12 @@ class Dot2c(Automata): return buff =20 def __get_max_strlen_of_states(self) -> int: - max_state_name =3D max(self.states, key =3D len).__len__() - return max(max_state_name, self.invalid_state_str.__len__()) + max_state_name =3D len(max(self.states, key=3Dlen)) + return max(max_state_name, len(self.invalid_state_str)) =20 def get_aut_init_function(self) -> str: - nr_states =3D self.states.__len__() - nr_events =3D self.events.__len__() + nr_states =3D len(self.states) + nr_events =3D len(self.events) buff =3D [] =20 maxlen =3D self.__get_max_strlen_of_states() + len(self.enum_suffi= x) --=20 2.52.0