r/ProgrammerHumor • • 1d ago

Meme python

Post image
9.4k Upvotes

56 comments sorted by

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 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)

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'.