Looks like the issue only occurs in PyCharm's Scratch files. I had the same problem and discovered that in regular project files it works fine. Feel free to upvote this issue.
Scratch