Right, Nick, I missed the part that you want to have a file-like wrapper stored in sys.std* streams that would redirect lookups/calls to the relevant real file-object in the current context (correct?) I has a similar idea when I discovered that PEP 550 can't be used directly to fix sys.std* streams redirection. Another idea: 1. We alter PyModule to make it possible to add properties (descriptor protocol, or we implement custom __getattr__). I think we can make it so that only sys module would be able to actually use it, so it's not going to be a new feature -- just a hack for CPython. 2. We make sys.std* attributes properties, with getters and setters. 3. sys.std* setters will: issue a DeprecationWarning; set whatever the user wants to set in a global variable + set a flag (let's call it "sys.__stdout_global_modified") that sys.std* were modified. 4. sys.std* getters will use PEP 550 to lookup when __stdout_global_modified is false. If it's true -- we fallback to globals. 5. We deprecate the current API and add new APIs for the redirection system that uses PEP 550 explicitly. 6. In Python 4 we remove the old sys.std* API. Thit is still *very* fragile: any code that writes to sys.stdout breaks all assumptions. But it offers a way to raise a warning when old-API is being used - something that we'll probably need if we add new APIs to fix this problem. Yury
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4