Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rv/rvgen: fix unbound loop variable warning

Pyright static analysis reports a "possibly unbound variable" warning
for the loop variable `i` in the `abbreviate_atoms` function. The
variable is accessed after the inner loop terminates to slice the atom
string. While the loop logic currently ensures execution, the analyzer
flags the reliance on the loop variable persisting outside its scope.

Refactor the prefix length calculation into a nested `find_share_length`
helper function. This encapsulates the search logic and uses explicit
return statements, ensuring the length value is strictly defined. This
satisfies the type checker and improves code readability without
altering the runtime behavior.

Signed-off-by: Wander Lairson Costa <wander@redhat.com>
Reviewed-by: Gabriele Monaco <gmonaco@redhat.com>
Link: https://lore.kernel.org/r/20260223162407.147003-19-wander@redhat.com
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>

authored by

Wander Lairson Costa and committed by
Gabriele Monaco
5d98f7f5 957dcbf0

+9 -5
+9 -5
tools/verification/rvgen/rvgen/ltl2k.py
··· 44 44 skip = ["is", "by", "or", "and"] 45 45 return '_'.join([x[:2] for x in s.lower().split('_') if x not in skip]) 46 46 47 - abbrs = [] 48 - for atom in atoms: 47 + def find_share_length(atom: str) -> int: 49 48 for i in range(len(atom), -1, -1): 50 49 if sum(a.startswith(atom[:i]) for a in atoms) > 1: 51 - break 52 - share = atom[:i] 53 - unique = atom[i:] 50 + return i 51 + return 0 52 + 53 + abbrs = [] 54 + for atom in atoms: 55 + share_len = find_share_length(atom) 56 + share = atom[:share_len] 57 + unique = atom[share_len:] 54 58 abbrs.append((shorten(share) + shorten(unique))) 55 59 return abbrs 56 60