Issue 11694: xdrlib raises ConversionError in inconsistent way (original) (raw)

Created on 2011-03-27 11:12 by gruszczy, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
11694.patch gruszczy,2011-09-17 10:59 review
issue11694.patch Claudiu.Popa,2014-10-09 19:16 review
Messages (10)
msg132309 - (view) Author: Filip Gruszczyński (gruszczy) Date: 2011-03-27 11:12
xdrlib defines ConversionError, but very seldom uses it. For example: def pack_float(self, x): try: self.__buf.write(struct.pack('>f', x)) except struct.error as msg: raise ConversionError(msg) But it doesn't do so here: def pack_uint(self, x): self.__buf.write(struct.pack('>L', x)) Shouldn't that be more consistent? I am happy to write a patch, that will make xdrlib raise ConversionError, as well as write proper test (I believe xdrlib tests should get some love altogether, so I would add a separate test case for this).
msg138783 - (view) Author: Petri Lehtinen (petri.lehtinen) * (Python committer) Date: 2011-06-21 12:30
This seems like a bug worth fixing. The ConversionError exception has been documented, an there's an example in the docs that suggest that at least all packing fails with a ConversionError.
msg144180 - (view) Author: Filip Gruszczyński (gruszczy) Date: 2011-09-17 10:59
Patch with tests.
msg151291 - (view) Author: Filip Gruszczyński (gruszczy) Date: 2012-01-15 15:50
Bump! It's almost 3 months since I posted the patch, so I would like to remind about this bug.
msg151293 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2012-01-15 16:54
Looks good to me.
msg162367 - (view) Author: Petri Lehtinen (petri.lehtinen) * (Python committer) Date: 2012-06-05 19:24
I see one obvious issue with the patch: The ConversionErrors it creates are passed the struct.error or TypeError instance as a parameter. The first argument of these exceptions would be better, i.e. try: ... except struct.error as e: raise ConversionError(e.args[0]) Furthermore, my ear thinks that raises_conversion_error would be a better name for the decorator than raising_conversion_error. Anyway, I think the whole ConversionError is a bit problematic, as either TypeError or ValueError would be the most appropriate exception, depending on the situation. For example: p = Packer() p.pack_int('foo') # should raise a TypeError p.pack_int(2**100) # should raise a ValueError This would be slightly harder to implement, though, as struct.error has exactly the same problem.
msg228893 - (view) Author: PCManticore (Claudiu.Popa) * (Python triager) Date: 2014-10-09 19:16
Here's a refreshed patch: - raising_conversion_error is now raise_conversion_error - the decorator uses functools.wraps - the ConversionError is instantiated with the first argument of the caught expression - the reraising of ConversionError has the exception context supressed.
msg228951 - (view) Author: Petri Lehtinen (petri.lehtinen) * (Python committer) Date: 2014-10-10 05:23
LGTM
msg229020 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-10-10 18:30
New changeset 9cee201388c9 by Petri Lehtinen in branch '2.7': Issue #11694: Raise ConversionError in xdrlib as documented https://hg.python.org/cpython/rev/9cee201388c9 New changeset 7ef6e5f53418 by Petri Lehtinen in branch '3.4': Issue #11694: Raise ConversionError in xdrlib as documented https://hg.python.org/cpython/rev/7ef6e5f53418 New changeset 8e3387f566f6 by Petri Lehtinen in branch 'default': #11694: merge with 3.4 https://hg.python.org/cpython/rev/8e3387f566f6
msg229021 - (view) Author: Petri Lehtinen (petri.lehtinen) * (Python committer) Date: 2014-10-10 18:33
Applied, thanks!
History
Date User Action Args
2022-04-11 14:57:15 admin set github: 55903
2014-10-10 18:33:54 petri.lehtinen set status: open -> closedresolution: fixedmessages: + stage: patch review -> resolved
2014-10-10 18:30:41 python-dev set nosy: + python-devmessages: +
2014-10-10 05:23:31 petri.lehtinen set messages: +
2014-10-09 19:16:06 Claudiu.Popa set files: + issue11694.patchmessages: + versions: + Python 3.4, Python 3.5, - Python 3.2, Python 3.3
2014-10-04 18:27:34 Claudiu.Popa set nosy: + Claudiu.Popa
2012-06-05 19:24:15 petri.lehtinen set messages: +
2012-01-15 16:54:32 georg.brandl set stage: test needed -> patch review
2012-01-15 16:54:21 georg.brandl set nosy: + georg.brandlmessages: +
2012-01-15 15:50:39 gruszczy set messages: +
2011-09-17 10:59:26 gruszczy set files: + 11694.patchkeywords: + patchmessages: +
2011-07-24 18:26:12 petri.lehtinen set stage: test neededversions: + Python 2.7, Python 3.2
2011-06-21 12:30:42 petri.lehtinen set nosy: + petri.lehtinenmessages: +
2011-03-27 11:12:16 gruszczy create