bskinn / stdio-mgr

Context manager for mocking/wrapping stdin/stdout/stderr
MIT License
14 stars 4 forks source link

Create ABC for .getvalue #86

Open jayvdb opened 5 years ago

jayvdb commented 5 years ago

stdio_mgr expects getvalue to exist on BytesIO, and previously expected it to exist on StringIO, and the docs still refer to StringIO.getvalue, but there is no base/abstract type which defines this.

>>> import io
>>> io.BytesIO.__class__.__mro__
(<class 'type'>, <class 'object'>)
>>> issubclass(io.BytesIO, io.IOBase)
True
>>> io.StringIO.__class__.__mro__
(<class 'type'>, <class 'object'>)
>>> issubclass(io.StringIO, io.IOBase)
True

There is nothing in https://github.com/python/typing or title search on bpo

We should create our own temporary ABC for this, so we can hang features on it, add new ones (like _PersistedFileIO as a BytesIO with a fileno()), and raise issues upstream about it. This is also 'needed' for bytes support (https://github.com/bskinn/stdio-mgr/issues/36) if we use strict type checking (https://github.com/bskinn/stdio-mgr/issues/60)

e.g. https://github.com/bskinn/stdio-mgr/issues/80 is a feature that depends on .getvalue and little else.

jayvdb commented 5 years ago

i.e. we need this .getvalue to exist on the TextIOWrapper instances, but it isnt defined as existing there.

bskinn commented 5 years ago

Agreed - we want this here, even if it's not found to be worth porting upstream into stdlib.

jayvdb commented 5 years ago

any naming suggestions?

jayvdb commented 5 years ago

AbstractIOValue?

bskinn commented 5 years ago

Thinking out loud---there will probably be more than just .getvalue() going into this, but it's hard to anticipate what it'll be at this point.

So, the name should be more general than just AbstractGetValueIO.