Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(791)

Issue 3245: #2415 bytes() should respect __bytes__ (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
15 years, 7 months ago by Benjamin
Modified:
14 years, 8 months ago
Reviewers:
barry
Base URL:
http://svn.python.org/view/*checkout*/python/branches/py3k/
Visibility:
Public.

Description

This patch allows classes to define __bytes__ to customize what bytes(obj) returns. I added two new C functions PyObject_Bytes, and PyBytes_FromObject.

Patch Set 1 #

Unified diffs Side-by-side diffs Delta from patch set Stats (+62 lines, -2 lines) Patch
Include/bytesobject.h View 1 chunk +1 line, -0 lines 0 comments Download
Include/object.h View 1 chunk +1 line, -0 lines 0 comments Download
Lib/test/test_bytes.py View 1 chunk +12 lines, -0 lines 0 comments Download
Objects/bytesobject.c View 2 chunks +9 lines, -2 lines 0 comments Download
Objects/object.c View 1 chunk +39 lines, -0 lines 2 comments Download

Messages

Total messages: 3
Benjamin
15 years, 7 months ago (2008-08-21 17:15:39 UTC) #1
barry
http://codereview.appspot.com/3245/diff/1/4 File Objects/object.c (right): http://codereview.appspot.com/3245/diff/1/4#newcode469 Line 469: return PyBytes_FromString("<NULL>"); Should this raise an exception instead? ...
15 years, 7 months ago (2008-08-26 09:05:15 UTC) #2
Benjamin
15 years, 7 months ago (2008-08-26 13:30:04 UTC) #3
On 2008/08/26 09:05:15, warsaw wrote:
> http://codereview.appspot.com/3245/diff/1/4
> File Objects/object.c (right):
> 
> http://codereview.appspot.com/3245/diff/1/4#newcode469
> Line 469: return PyBytes_FromString("<NULL>");
> Should this raise an exception instead?  What's the use case for allowing v ==
> NULL?

I did this because this is what PyObject_Str does if the value is NULL.
> 
> http://codereview.appspot.com/3245/diff/1/4#newcode491
> Line 491: PyErr_Clear();
> Should this swallow all lookup errors or just more specific ones indicating
> __bytes__ doesn't exist?

This is also the behavior of 2.6's PyObject_Unicode if the lookup returns NULL.
I personally think that it could check for an attribute error, but I guess that
might be expensive.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b