Unexpected behavior while monitoring key press and release

Hey everyone,
I want to monitor when space bar is pressed and released again. I would like to monitor press and release as separate events. However, I encountered an unexpected behavior which can be reproduced with this example

from psychopy.hardware import keyboard
kb = keyboard.Keyboard()

for i in range(5):
    kb.clearEvents()
    key = kb.waitKeys(keyList=["space"], waitRelease=False) # wait for press
    print("press!")
    key = kb.waitKeys(  # wait for release
        maxWait=1,
        keyList=["space"],
        waitRelease=True,
        clear=False,
    )
    print("release!")
    print(key)
    del key

On the first iteration of the loop, it is working as expected: After pressing space I see the printout "press!" and if I keep holding it down until maxWait has passed I see "release!" and the value of the key variable will be None. However, on the second iteration, it immediately jumps from "press!" to "release!" and key contains a key press. Why does this happen? Shouldn’t calling clearEvents() clear all key presses? I played around with the clear argument of the waitKeys() method, but it had no effect on this behavior. Not sure if this is a bug, or I don’t understand how the kbQueue works …

If you hold a key down it starts sending a string of key presses.

I understand that, but why is the code behaving differently on the first iteration?
The first call to waitKeys should monitor the press the second one the release. This works the first time but not after that

I found that calling getKeys() in between the two calls to waitKeys() fixes the problem. However, it is beyond me why this would happen.

from psychopy.hardware import keyboard
kb = keyboard.Keyboard()

for i in range(5):
    kb.clearEvents()
    key = kb.waitKeys(keyList=["space"], waitRelease=False) # wait for press
    print("press!")
    kb.getKeys()  # this is somehow necessary
    key = kb.waitKeys(  # wait for release
        maxWait=1,
        keyList=["space"],
        waitRelease=True,
        clear=False,
    )
    print("release!")
    print(key)
    del key