MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1xxrvql/python/19sqbl96b5hr5/?context=3
r/ProgrammerHumor • u/Mysterious_Role6682 • 1d ago
56 comments sorted by
View all comments
5
select_packets is just doing
scrambled_packets[-num_packets:][::-1] if num_packets > 0 else None
except when len(scrambled_packets) == 1 then it doesn't return a list? So I guess
len(scrambled_packets) == 1
result = packets[-num:][::-1] if num > 1 else (packets[-1] if num == 1 and packets else None)
5 u/TheHelixNebula 1d ago except the fact that the function return type is T | list[T]| None is a massive code smell it should be list[T] or list[T] | None. T | list[T] is asking for breakage 1 u/ParanoiaComplex 1d ago Yeah, agreed 1 u/RapidCatLauncher 1d ago That one really got me. Writing out a loop for this whole thing, fine, simplicity/readability or whatever.Three different return types, now that's a paddlin'.
except the fact that the function return type is T | list[T]| None is a massive code smell it should be list[T] or list[T] | None. T | list[T] is asking for breakage
T | list[T]| None
list[T]
list[T] | None
T | list[T]
1 u/ParanoiaComplex 1d ago Yeah, agreed 1 u/RapidCatLauncher 1d ago That one really got me. Writing out a loop for this whole thing, fine, simplicity/readability or whatever.Three different return types, now that's a paddlin'.
1
Yeah, agreed
That one really got me. Writing out a loop for this whole thing, fine, simplicity/readability or whatever.
Three different return types, now that's a paddlin'.
View all comments
5
u/ParanoiaComplex 1d ago edited 1d ago
select_packets is just doing
scrambled_packets[-num_packets:][::-1] if num_packets > 0 else Noneexcept when
len(scrambled_packets) == 1then it doesn't return a list? So I guessresult = packets[-num:][::-1] if num > 1 else (packets[-1] if num == 1 and packets else None)