3.4 and 3.5 only get security fixes and I doubt this qualifies.
I reproduced the described behavior with 3.7 on Win 10, so it is not Mac-specific.
Python sys.stdout: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
IDLE's sys.stdout: <idlelib.run.PseudoOutputFile object at 0x00000246821B1E10>
The PseudoFiles are unusual in being internal objects accessible from user code.
Comparing attributes with public names (not starting with single or double underscore) PseudoOutputFile lacks buffer, line_buffering, mode, reconfigure, and write_through. #21995 is about fixing or documenting each omission for all 3 streams.
PseudoFiles add shell and tags. Both should have private names that warn users that their behavior is undocumented and usage is at one's own risk. 'shell' should be double underscored. This minimal fix would be sufficient to close this issue. Some manual testing should be sufficient for such a change.
'Tags' should be singular, as it is one of 'stdin', 'stdout', or 'stderr'. The tag is used in the write method to tell Shell whether to display with the configured stdout or stderr colors.
Shell is an idlelib.rpc.RPCProxy object. As an object in itself, in the run process, it has 2 public attributes: oid ('console') and sockio (an idlelib.run.MyHandler object). But as a proxy representing the Shell console object in the IDLE process, it supposedly 'has' all the attributes of the latter. These are accessed with a custom __getattr__.
def __getattr__(self, name):
if self.__methods is None:
self.__getmethods()
if self.__methods.get(name):
return MethodProxy(self.sockio, self.oid, name)
if self.__attributes is None:
self.__getattributes()
if name in self.__attributes:
value = self.sockio.remotecall(self.oid, '__getattribute__',
(name,), {})
return value
else:
raise AttributeError(name)
Note that self.__attributes is mangled to shell._RPCProxy__attributes when accessed externally. (Also, it is a set still implemented in this ancient code as a dict with int 1 values.)
More importantly, remote calls to the Shell console can only pass and return objects that can be pickled, and there is currently no provision for graceful failure. Hence sys.stdout.shell.width is (for me, currently) 80, but .console or .stdout are impossible to return.
I am extremely dubious about trying to fix this in the IDLE side of the link. Instead, the proxy should be initialized with sets of known usable attributes and methods. I think the underlying problem is trying to be unnecessarily and impossibly generic. Run only calls the .readline, .write, and .close methods of the console proxy. It only calls stack viewer setup on the interp proxy. A third proxy, for flist, is passed to the stack viewer (I have not yet checked what is needed for that). Restricting proxies to things that are needed and *should* work would make it more feasible to test them. But setting up automated tests would still require some work.
|