mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 06:44:00 -04:00
rv/rvgen: replace __len__() calls with len()
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 <wander@redhat.com> Reviewed-by: Gabriele Monaco <gmonaco@redhat.com> Reviewed-by: Nam Cao <namcao@linutronix.de> Link: https://lore.kernel.org/r/20260223162407.147003-5-wander@redhat.com Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
This commit is contained in:
committed by
Gabriele Monaco
parent
908f377f4a
commit
b70bc5cca0
@@ -82,7 +82,7 @@ class Automata:
|
||||
raise AutomataError(f"not a dot file: {self.__dot_path}")
|
||||
|
||||
model_name = ntpath.splitext(basename)[0]
|
||||
if model_name.__len__() == 0:
|
||||
if not model_name:
|
||||
raise AutomataError(f"not a dot file: {self.__dot_path}")
|
||||
|
||||
return model_name
|
||||
|
||||
@@ -96,14 +96,14 @@ class Dot2c(Automata):
|
||||
def get_minimun_type(self) -> str:
|
||||
min_type = "unsigned char"
|
||||
|
||||
if self.states.__len__() > 255:
|
||||
if len(self.states) > 255:
|
||||
min_type = "unsigned short"
|
||||
|
||||
if self.states.__len__() > 65535:
|
||||
if len(self.states) > 65535:
|
||||
min_type = "unsigned int"
|
||||
|
||||
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)}")
|
||||
|
||||
return min_type
|
||||
|
||||
@@ -159,12 +159,12 @@ class Dot2c(Automata):
|
||||
return buff
|
||||
|
||||
def __get_max_strlen_of_states(self) -> int:
|
||||
max_state_name = max(self.states, key = len).__len__()
|
||||
return max(max_state_name, self.invalid_state_str.__len__())
|
||||
max_state_name = len(max(self.states, key=len))
|
||||
return max(max_state_name, len(self.invalid_state_str))
|
||||
|
||||
def get_aut_init_function(self) -> str:
|
||||
nr_states = self.states.__len__()
|
||||
nr_events = self.events.__len__()
|
||||
nr_states = len(self.states)
|
||||
nr_events = len(self.events)
|
||||
buff = []
|
||||
|
||||
maxlen = self.__get_max_strlen_of_states() + len(self.enum_suffix)
|
||||
|
||||
Reference in New Issue
Block a user