Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed1.swip.net!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.06; 'explicit': 0.07; 'reason,': 0.07; 'suppose': 0.07; 'function,': 0.09; 'method,': 0.09; 'subject:method': 0.09; 'cc:addr:python- list': 0.11; 'jan': 0.12; 'accepts': 0.16; 'better?': 0.16; 'expecting': 0.16; 'subclass': 0.16; 'unlikely': 0.16; 'sat,': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'bytes': 0.24; 'of.': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'daniel': 0.26; 'header:In- Reply-To:1': 0.27; 'function': 0.29; 'message-id:@mail.gmail.com': 0.30; 'object.': 0.31; 'cases': 0.33; 'skip:_ 10': 0.34; 'agree': 0.35; 'objects': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'object,': 0.36; 'behind': 0.37; 'so,': 0.37; 'two': 0.37; 'skip:o 20': 0.38; 'pm,': 0.38; 'does': 0.39; 'guaranteed': 0.75; 'ethan': 0.84; 'furman': 0.84; 'realistic': 0.93; 'logistics': 0.95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=0cu/6rbvUfjlkMXMp/G3kwwR2KaMHJO0PPQN0MdaZog=; b=W3BDdPoEdN/FEVE9uus6IlLnijmajWVXzp0mDCdLvBDc1rg6ppHS/ZYcCBbyg0Oo6+ IXgNj0Aa076xc1LYObRoyltLA6g72dfEensh/ZpuMXlDEiMPiWsThfOXpu5oV0kgj7Nd YM9B5hGYtqOOyFtH64FPZRMFUJK6W4ZKippf2cxqPWn/uEzRiwyh8REB4T4zEO7wWSPV prG/mp3XM/Iw82GV3nt56au39okAa5SrclNOqR4tA6B+j7VI2g92Tzf+Gcx1MzPInqDJ mqekvII/PO9bXNV/lULobyY8gW6M7KS68iHywVNIWL3WGSm/v14ii7c/P3K1jZAo7CKB VWxQ== MIME-Version: 1.0 X-Received: by 10.180.20.15 with SMTP id j15mr9622645wie.4.1389502602113; Sat, 11 Jan 2014 20:56:42 -0800 (PST) Sender: meltingwax@gmail.com In-Reply-To: <52D201A7.3050403@stoneleaf.us> References: <52D1E0CE.5030906@stoneleaf.us> <52D1E830.8070305@stoneleaf.us> <52D201A7.3050403@stoneleaf.us> Date: Sat, 11 Jan 2014 23:56:42 -0500 X-Google-Sender-Auth: mE_b_nurnsWfQniwaUeB9nl9Il4 Subject: Re: Python 3 __bytes__ method From: Daniel da Silva To: Ethan Furman Content-Type: multipart/alternative; boundary=bcaec53f39850378c304efbec967 X-Mailman-Approved-At: Sun, 12 Jan 2014 07:39:29 +0100 Cc: Python X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 72 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389508769 news.xs4all.nl 2946 [2001:888:2000:d::a6]:53591 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63755 --bcaec53f39850378c304efbec967 Content-Type: text/plain; charset=ISO-8859-1 On Sat, Jan 11, 2014 at 9:44 PM, Ethan Furman wrote: > On 01/11/2014 06:19 PM, Daniel da Silva wrote: > >> >> One use case is: >> Suppose you have existing function that accepts a /bytes/ object. If you >> subclass /bytes/ and want it to be guaranteed >> to work with that function, you can override/__bytes__()/ to use the >> logistics of your subclass implementation. >> > > I don't think so, for two reasons: > > 1) bytes objects do not have a __bytes__ method, > > 2) if the function is expecting a bytes object, it is unlikely to call > bytes() on it. In general __typename__() methods are for explicit typename(obj) conversion. There is __int__(), __str__(), etc. They are what is behind int('3') == 3 and str(4) == '4'. If for no other reason, __bytes__() is there for symmetry. I agree with you that realistic use cases are hard to think of. Does that answer your question better? All the best, Daniel --bcaec53f39850378c304efbec967 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable



On Sat, Jan 11, 2014 at 9:44 PM, Ethan Furman <= ;ethan@stoneleaf.us= > wrote:
On 01/11/2014 06:19 PM, Daniel da Silva = wrote:

One use case is:
Suppose you have existing function that accepts a /bytes/ object. If you su= bclass /bytes/ and want it to be guaranteed
to work with that function, you can override/__bytes__()/ to use the logist= ics of your subclass implementation.

I don't think so, for two reasons:

1) bytes objects do not have a __bytes__ method,

2) if the function is expecting a bytes object, it is unlikely to call byte= s() on it.

In general __typename__() method= s are for explicit typename(obj) conversion. There is __int__(), __str__(),= etc. They are what is behind int('3') =3D=3D 3 and str(4) =3D=3D &= #39;4'. If for no other reason, __bytes__() is there for symmetry. I ag= ree with you that realistic use cases are hard to think of.

Does that answer your question better?=A0
All the best,
Daniel
--bcaec53f39850378c304efbec967--