CLN: PY3 String/BytesIO
State: closed

- [x] xref #25725
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`

Imports `StringIO` and `BytesIO` from `io`. Removes `cStringIO`

Labels:
name: Clean

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25954?src=pr&el=h1) Report
> Merging [#25954](https://codecov.io/gh/pandas-dev/pandas/pull/25954?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/00c119c50728bee88a5e5d1538cf3a405e36997c?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `91.3%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/25954/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/25954?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #25954      +/-   ##
==========================================
- Coverage   91.82%   91.81%   -0.01%     
==========================================
  Files         175      175              
  Lines       52581    52584       +3     
==========================================
+ Hits        48280    48282       +2     
- Misses       4301     4302       +1
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.37% <91.3%> (ø)` | :arrow_up: |
| #single | `41.9% <73.91%> (-0.07%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/25954?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/compat/\_\_init\_\_.py](https://codecov.io/gh/pandas-dev/pandas/pull/25954/diff?src=pr&el=tree#diff-cGFuZGFzL2NvbXBhdC9fX2luaXRfXy5weQ==) | `71.71% <ø> (+1%)` | :arrow_up: |
| [pandas/io/formats/format.py](https://codecov.io/gh/pandas-dev/pandas/pull/25954/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvZm9ybWF0LnB5) | `97.89% <100%> (ø)` | :arrow_up: |
| [pandas/io/json/json.py](https://codecov.io/gh/pandas-dev/pandas/pull/25954/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2pzb24vanNvbi5weQ==) | `93.24% <100%> (+0.01%)` | :arrow_up: |
| [pandas/io/common.py](https://codecov.io/gh/pandas-dev/pandas/pull/25954/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2NvbW1vbi5weQ==) | `91.87% <100%> (ø)` | :arrow_up: |
| [pandas/io/formats/csvs.py](https://codecov.io/gh/pandas-dev/pandas/pull/25954/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvY3N2cy5weQ==) | `98.2% <100%> (ø)` | :arrow_up: |
| [pandas/core/series.py](https://codecov.io/gh/pandas-dev/pandas/pull/25954/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc2VyaWVzLnB5) | `93.67% <100%> (ø)` | :arrow_up: |
| [pandas/core/computation/expr.py](https://codecov.io/gh/pandas-dev/pandas/pull/25954/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tcHV0YXRpb24vZXhwci5weQ==) | `88.55% <100%> (+0.02%)` | :arrow_up: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/25954/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `96.79% <100%> (-0.12%)` | :arrow_down: |
| [pandas/core/computation/scope.py](https://codecov.io/gh/pandas-dev/pandas/pull/25954/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tcHV0YXRpb24vc2NvcGUucHk=) | `93.13% <100%> (+0.06%)` | :arrow_up: |
| [pandas/io/clipboards.py](https://codecov.io/gh/pandas-dev/pandas/pull/25954/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2NsaXBib2FyZHMucHk=) | `100% <100%> (ø)` | :arrow_up: |
| ... and [5 more](https://codecov.io/gh/pandas-dev/pandas/pull/25954/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25954?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25954?src=pr&el=footer). Last update [00c119c...bead183](https://codecov.io/gh/pandas-dev/pandas/pull/25954?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25954?src=pr&el=h1) Report
> Merging [#25954](https://codecov.io/gh/pandas-dev/pandas/pull/25954?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/f90f4aad4589727ebb3235326970a9110aaa309f?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `92%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/25954/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/25954?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #25954      +/-   ##
==========================================
- Coverage   91.84%   91.84%   -0.01%     
==========================================
  Files         175      175              
  Lines       52553    52552       -1     
==========================================
- Hits        48269    48267       -2     
- Misses       4284     4285       +1
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.4% <92%> (ø)` | :arrow_up: |
| #single | `41.9% <76%> (-0.07%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/25954?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/compat/\_\_init\_\_.py](https://codecov.io/gh/pandas-dev/pandas/pull/25954/diff?src=pr&el=tree#diff-cGFuZGFzL2NvbXBhdC9fX2luaXRfXy5weQ==) | `74.43% <ø> (+1.24%)` | :arrow_up: |
| [pandas/io/formats/format.py](https://codecov.io/gh/pandas-dev/pandas/pull/25954/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvZm9ybWF0LnB5) | `97.89% <100%> (ø)` | :arrow_up: |
| [pandas/io/json/json.py](https://codecov.io/gh/pandas-dev/pandas/pull/25954/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2pzb24vanNvbi5weQ==) | `93.24% <100%> (+0.01%)` | :arrow_up: |
| [pandas/io/common.py](https://codecov.io/gh/pandas-dev/pandas/pull/25954/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2NvbW1vbi5weQ==) | `91.87% <100%> (ø)` | :arrow_up: |
| [pandas/io/formats/csvs.py](https://codecov.io/gh/pandas-dev/pandas/pull/25954/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvY3N2cy5weQ==) | `98.2% <100%> (ø)` | :arrow_up: |
| [pandas/core/series.py](https://codecov.io/gh/pandas-dev/pandas/pull/25954/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc2VyaWVzLnB5) | `93.67% <100%> (ø)` | :arrow_up: |
| [pandas/core/computation/expr.py](https://codecov.io/gh/pandas-dev/pandas/pull/25954/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tcHV0YXRpb24vZXhwci5weQ==) | `88.55% <100%> (+0.02%)` | :arrow_up: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/25954/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `96.79% <100%> (-0.12%)` | :arrow_down: |
| [pandas/core/computation/scope.py](https://codecov.io/gh/pandas-dev/pandas/pull/25954/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tcHV0YXRpb24vc2NvcGUucHk=) | `93.13% <100%> (+0.06%)` | :arrow_up: |
| [pandas/io/clipboards.py](https://codecov.io/gh/pandas-dev/pandas/pull/25954/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2NsaXBib2FyZHMucHk=) | `100% <100%> (ø)` | :arrow_up: |
| ... and [8 more](https://codecov.io/gh/pandas-dev/pandas/pull/25954/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25954?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25954?src=pr&el=footer). Last update [f90f4aa...250812d](https://codecov.io/gh/pandas-dev/pandas/pull/25954?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

@WillAyd mind helping me interpret these typing errors (not too familiar with mypy)?

```
pandas/io/common.py:414: error: Definition of "__enter__" in base class "ZipFile" is incompatible with definition in base class "BytesIO"
pandas/io/common.py:414: error: Definition of "__enter__" in base class "ZipFile" is incompatible with definition in base class "BinaryIO"
pandas/io/common.py:414: error: Definition of "__enter__" in base class "ZipFile" is incompatible with definition in base class "IO"
pandas/io/common.py:414: error: Definition of "__exit__" in base class "ZipFile" is incompatible with definition in base class "BytesIO"
pandas/io/common.py:414: error: Definition of "read" in base class "ZipFile" is incompatible with definition in base class "BytesIO"
pandas/io/common.py:414: error: Definition of "read" in base class "ZipFile" is incompatible with definition in base class "IO"
pandas/io/common.py:414: error: Definition of "write" in base class "ZipFile" is incompatible with definition in base class "BytesIO"
pandas/io/common.py:414: error: Definition of "write" in base class "ZipFile" is incompatible with definition in base class "BinaryIO"
pandas/io/common.py:414: error: Definition of "write" in base class "ZipFile" is incompatible with definition in base class "IO"
```

AFAICT, it has to do with this class defintion

https://github.com/pandas-dev/pandas/blob/f90f4aad4589727ebb3235326970a9110aaa309f/pandas/io/common.py#L414
Not at a computer to check but I think this happens if a subclass overrides a method with a signature that varies from the parent class. 

I’ll see what I can dig up

Sent from my iPhone

> On Apr 2, 2019, at 1:14 PM, Matthew Roeschke <notifications@github.com> wrote:
> 
> @WillAyd mind helping me interpret these typing errors (not too familiar with mypy)?
> 
> pandas/io/common.py:414: error: Definition of "__enter__" in base class "ZipFile" is incompatible with definition in base class "BytesIO"
> pandas/io/common.py:414: error: Definition of "__enter__" in base class "ZipFile" is incompatible with definition in base class "BinaryIO"
> pandas/io/common.py:414: error: Definition of "__enter__" in base class "ZipFile" is incompatible with definition in base class "IO"
> pandas/io/common.py:414: error: Definition of "__exit__" in base class "ZipFile" is incompatible with definition in base class "BytesIO"
> pandas/io/common.py:414: error: Definition of "read" in base class "ZipFile" is incompatible with definition in base class "BytesIO"
> pandas/io/common.py:414: error: Definition of "read" in base class "ZipFile" is incompatible with definition in base class "IO"
> pandas/io/common.py:414: error: Definition of "write" in base class "ZipFile" is incompatible with definition in base class "BytesIO"
> pandas/io/common.py:414: error: Definition of "write" in base class "ZipFile" is incompatible with definition in base class "BinaryIO"
> pandas/io/common.py:414: error: Definition of "write" in base class "ZipFile" is incompatible with definition in base class "IO"
> AFAICT, it has to do with this class defintion
> 
> https://github.com/pandas-dev/pandas/blob/f90f4aad4589727ebb3235326970a9110aaa309f/pandas/io/common.py#L414
> 
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub, or mute the thread.

So the error messages here are rather explicit; the problem is that with multiple inheritance the two classes that object derives from has conflicting signatures. Here's a related issue on the MyPy tracker:

https://github.com/python/mypy/issues/2125

This code is pretty tricky though - do you see a test case that actually hits this? Actually wondering if multiple inheritance is even required or if it can subclass ZipFile directly, given it's constructor matches that and the call to `writestr` can accept bytes or str anyway. 

If not then ignoring the types might be the only way to go about this
Thanks for the tips @WillAyd. Since this PR isn't concerned with typing just ignoring the typing check for the `BytesZipFile` class. 
thanks @mroeschke 

@WillAyd its ok to ignore these for now; can circle back later (maybe even add a check to detect types we are ignoring).