[issue17309] __bytes__ doesn't work in subclass of int and str

2013-03-02 Thread Benjamin Peterson
Benjamin Peterson added the comment: This has been fixed recently: $ ./python bytes.py b'\x00' b'hello' -- nosy: +benjamin.peterson resolution: -> out of date status: open -> closed ___ Python tracker _

[issue17309] __bytes__ doesn't work in subclass of int and str

2013-03-01 Thread Terry J. Reedy
Terry J. Reedy added the comment: More data: class myit(list): def __bytes__(self): return b'hello' print (bytes(b'a')) class myit(list): def __bytes__(self): return b'hello' print (bytearray (myit([1,2,3]))) # bytearray(b'a') # bytearray(b'\x01\x02\x03') class by: def __bytes__(s

[issue17309] __bytes__ doesn't work in subclass of int and str

2013-03-01 Thread Terry J. Reedy
Terry J. Reedy added the comment: The library doc says that if the source argument for bytes() or bytearray() is a string or integer it is treated a certain way. I believe 'string' and 'integer' are meant to include subclasses of str and int, else it should have said str or int. You have verif

[issue17309] __bytes__ doesn't work in subclass of int

2013-02-27 Thread Paul Koning
New submission from Paul Koning: The __bytes__ special method has no effect in a subclass of "int" because the bytes() builtin checks for int or int subclass before it gets around to looking for that special method. The attached example shows it. -- components: Interpreter Core files: