Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix method delegation in _flushfile #175

Merged
merged 2 commits into from
Dec 17, 2023
Merged

Fix method delegation in _flushfile #175

merged 2 commits into from
Dec 17, 2023

Conversation

aivarannamaa
Copy link
Contributor

@aivarannamaa aivarannamaa commented Sep 23, 2023

The change is required when the stream to be wrapped is already a wrapper over the original std-stream and the wrapper also uses method delegation via __getattr__.

I discovered this issue when investigating thonny/thonny#2924

Thonny IDE fakes the standard streams before running the code using cs05, which tries to add another wrapper over these faked streams. The problem is that cs50's object.__getattribute__(self.f, name) only sees the methods defined directly in Thonny's FakeStream and does not consider the methods available via __getattr__.

The built-in getattr proposed in this PR is able to look deeper.

For extra confidence you could investigate this SO answer, which also uses getattr: https://stackoverflow.com/a/107717/261181

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Required when the faked stream is already faked and the original fake also uses method delegation.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Fix method delegation in _flushfile
@dmalan dmalan merged commit 62ad33c into cs50:main Dec 17, 2023
@dmalan
Copy link
Member

dmalan commented Dec 17, 2023

Thank you for this, @aivarannamaa!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants