python / python/mypy

mypyc: Any subclass of BytesIO will always generate an exception when instantiated

Offen
#16,209 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug topic-mypyc
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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.

TestSubclassingBytesIO.zip

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, TestSubclassingBytesIO.zip zu extrahieren und TestSubclassingBytesIO.py vor und nach dem Kompilieren von SubclassingBytesIO.py mit mypyc auszuführen. Vergleiche die Instanziierungspfade von BytesIO und SubBytesIO; abgeschlossen ist die Aufgabe, wenn das kompilierte Skript beide Instanzen ausgibt, ohne BufferError auszulösen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
compilers
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.