Skip to content

Fix AttributeError: KeyboardDevice missing _buffers attribute wo PTB#7494

Merged
peircej merged 1 commit intopsychopy:devfrom
wadelab:fix-keyboard-buffers-attribute-error
Jan 21, 2026
Merged

Fix AttributeError: KeyboardDevice missing _buffers attribute wo PTB#7494
peircej merged 1 commit intopsychopy:devfrom
wadelab:fix-keyboard-buffers-attribute-error

Conversation

@wadelab
Copy link
Copy Markdown
Contributor

@wadelab wadelab commented Dec 10, 2025

Problem

When trying to play a movie clip (mp4 container) from a local drive, KeyboardDevice crashes with AttributeError: 'KeyboardDevice' object has no attribute '_buffers' when using non-PTB backends (iohub or event). I think this is because these attributes are only initialized in the PTB backend branch (but I'm not using that)

Solution

Just initialize _buffers and _devs as empty dicts at the end of __init__. This ensures the attributes exist even when the PTB backend is not used. I think all actual usages of these attributes have other checks, so empty dicts should be harmless. I think....

Testing

Tested with movie playback using iohub backend - previously crashed, now works correctly! Also the movie plays very smoothly.

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 10, 2025

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.31%. Comparing base (abb674c) to head (a8162bc).
⚠️ Report is 109 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #7494      +/-   ##
==========================================
- Coverage   48.93%   48.31%   -0.63%     
==========================================
  Files         355      355              
  Lines       64990    65250     +260     
==========================================
- Hits        31806    31524     -282     
- Misses      33184    33726     +542     
Components Coverage Δ
app ∅ <ø> (∅)
boilerplate ∅ <ø> (∅)
library ∅ <ø> (∅)
vm-safe library ∅ <ø> (∅)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@TEParsons
Copy link
Copy Markdown
Contributor

Thanks for catching this! The test fails are due to GitHub deprecating the version of Mac OS we were using for the runners - I've just pulled in a fix to the release branch and am currently merging those changes into the dev branch, so once this PR is in:
#7503

you should be able to merge from the dev branch and have tests pass. Once they do I'm happy to pull this in :)

@peircej peircej merged commit 5c6b097 into psychopy:dev Jan 21, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants