Fix method delegation in _flushfile
#175
Merged
+1
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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