mypyc: Any subclass of BytesIO will always generate an exception when instantiated
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
Any subclass of BytesIO will always generate the following exception when instantiated:
BufferError: Existing exports of data: object cannot be re-sized
To Reproduce
1. Run TestSubclassingBytesIO.py and notice it prints two instances (one of BytesIO and the other of SubBytesIO)
2. Using mypyc compile the 4 line file: SubclassingBytesIO.py
3. Then again run the tiny TestSubclassingBytesIO.py
4. The run will crash with the mentioned exception.
Expected Behavior
Running TestSubclassingBytesIO.py after compiling with mypyc should work just like running it before compiling. It should print:
<_io.BytesIO object at 0x0000026903075BC0>
<SubclassingBytesIO.SubBytesIO object at 0x00000269030A0630>
Actual Behavior
<_io.BytesIO object at 0x00000238D1D95BC0>
Traceback (most recent call last):
File "c:\Projects\mypycbug\TestSubclassingBytesIO.py", line 7, in
x = SubBytesIO()
^^^^^^^^^^^^
BufferError: Existing exports of data: object cannot be re-sized
Your Environment
- Mypy version used: 1.5.1
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.11.4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by extracting the attached TestSubclassingBytesIO.zip and running TestSubclassingBytesIO.py before and after compiling SubclassingBytesIO.py with mypyc. Compare the BytesIO and SubBytesIO instantiation paths; done means the compiled script prints both instances without raising BufferError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100