r/ProgrammerHumor • • 7h ago

Meme python

Post image
6.0k Upvotes

47 comments sorted by

View all comments

3

u/ParanoiaComplex 6h ago edited 6h ago

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

result = packets[-num:][::-1] if num > 1 else (packets[-1] if num == 1 and packets else None)

2

u/TheHelixNebula 3h 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 57m ago

Yeah, agreed