Hi everyone,
In PyShp, we've had informal legacy support for every single text codec in Python (91 of them), and I've only recently got around to adding tests for these. Hypothesis has been incredibly helpful for that, and helped both uncover some lurking bugs, and point the way to making our unicode handling robust. Huge thanks to the whole team.
There were just a few issues I had to add custom code for, that I think must also be applicable to any project that round trips strings to bytes via all the unicode codecs.
Firstly there are stateful codecs such as the ISO 2002 ones. Even though I added exclude_categories=["Cs", "Co", "Cn"], the characters strategy, with the codec "iso2022_jp" for example still presumably draws from Python's entire quick mapping which includes, the codec's custom (non-unicode control-char-categorised) control char: '\x1b' This can indeed be encoded, but decoding the result (b'\x1b') back again errors.
Secondly there are non-injective codecs. Under these two code points can encode to the same bytes. I don't know of any stochastic codecs (thankfully) so for now they can all only decode these bytes to one of them. I would like a strategy (or an option in characters) to omit the ones, that cannot be restored by decoded its encoded bytes back again. E.g under "cp950", "•" (U+2022) and "" (U+2027) both encode to b'\xa1E'
>>> enc = "cp950"
>>> "•".encode(enc) == "‧".encode(enc)
True
Is there any interest in adding some options, so that users can instruct hypothesis to avoid generating these troublesome characters, for these codecs? Currently I hardcode a few codecs, and assemble a custom list of exclude_characters along with each codec.
Thanks,
Hi everyone,
In PyShp, we've had informal legacy support for every single text codec in Python (91 of them), and I've only recently got around to adding tests for these. Hypothesis has been incredibly helpful for that, and helped both uncover some lurking bugs, and point the way to making our unicode handling robust. Huge thanks to the whole team.
There were just a few issues I had to add custom code for, that I think must also be applicable to any project that round trips strings to bytes via all the unicode codecs.
Firstly there are stateful codecs such as the ISO 2002 ones. Even though I added
exclude_categories=["Cs", "Co", "Cn"], the characters strategy, with the codec"iso2022_jp"for example still presumably draws from Python's entire quick mapping which includes, the codec's custom (non-unicode control-char-categorised) control char:'\x1b'This can indeed be encoded, but decoding the result (b'\x1b') back again errors.Secondly there are non-injective codecs. Under these two code points can encode to the same bytes. I don't know of any stochastic codecs (thankfully) so for now they can all only decode these bytes to one of them. I would like a strategy (or an option in characters) to omit the ones, that cannot be restored by decoded its encoded bytes back again. E.g under
"cp950","•"(U+2022) and""(U+2027) both encode tob'\xa1E'Is there any interest in adding some options, so that users can instruct hypothesis to avoid generating these troublesome characters, for these codecs? Currently I hardcode a few codecs, and assemble a custom list of exclude_characters along with each codec.
Thanks,