Skip to content

Fix method delegation in _flushfile #1

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

Merged
merged 1 commit into from
Sep 23, 2023

Conversation

aivarannamaa
Copy link
Owner

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

Required when the faked stream is already faked and the original fake also uses method delegation.
@aivarannamaa aivarannamaa merged commit c5b093f into main Sep 23, 2023
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.

1 participant