[Python-Dev] Scope, not context? (was Re: PEP 550 v3 naming) (original) (raw)
Yury Selivanov yselivanov.ml at gmail.com
Fri Aug 25 10🔞55 EDT 2017
- Previous message (by thread): [Python-Dev] Scope, not context? (was Re: PEP 550 v3 naming)
- Next message (by thread): [Python-Dev] Scope, not context? (was Re: PEP 550 v3 naming)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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:
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.
We make sys.std* attributes properties, with getters and setters.
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.
sys.std* getters will use PEP 550 to lookup when __stdout_global_modified is false. If it's true -- we fallback to globals.
We deprecate the current API and add new APIs for the redirection system that uses PEP 550 explicitly.
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
- Previous message (by thread): [Python-Dev] Scope, not context? (was Re: PEP 550 v3 naming)
- Next message (by thread): [Python-Dev] Scope, not context? (was Re: PEP 550 v3 naming)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]