GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||
GeezerVison is showing github.com — io: TextIOWrapper silently corrupts output when encoder is a no-op · Issue #161518 · python/cpython Open Labels extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-IOtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error DescriptionBug reportSummaryWhen an encoder returns the input str itself, Expected: ReproducerWe use a 44-character string that ends in an emoji, so CPython internally stores it as four bytes per character. import codecs class Enc(codecs.IncrementalEncoder): def encode(self, text, final=False): return text info = codecs.CodecInfo(None, None, incrementalencoder=Enc, incrementaldecoder=codecs.getincrementaldecoder("utf-8"), name="passthrough") codecs.register(lambda n: info if n == "passthrough" else None) with open("out.txt", "w", encoding="passthrough") as f: f.write("The quick brown fox jumps over the lazy dog🐍") print(open("out.txt").read()) The quick bOnly the first 44 bytes (out of 44*4 = 176) were written to the file. Root cause
Line 1834 in d900c8f
The exemption for A Python encoder that returns its input also satisfies it, with any text. Suggested fixTie the exemption to what the fast path relies on, that the text is ASCII: if (!PyBytes_Check(b) && !(b == text && PyUnicode_IS_ASCII(text))) { With this the reproducer raises the TypeError above. CPython versions tested on:CPython main branch Operating systems tested on:Linux Linked PRsActivity
MetadataMetadataAssigneesLabelsextension-modulesC modules in the Modules dirC modules in the Modules dirtopic-IOtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error ProjectsMilestoneRelationshipsDevelopmentIssue actions | ||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |