On Wed, Nov 25, 2009 at 9:04 AM, Stefan Behnel <[email protected]> wrote:
>
> Joachim Saul, 25.11.2009 11:07:
>> Joachim Saul:
>>> I would assume that in addition to None, any value that is acceptable as
>>> argument to bytes() should also be acceptable as a default value for a
>>> bytes-type parameter, following the Rule of Least Surprize™. This would
>>> consequently also allow code such as
>>>
>>> def foo(bytes bar=5):
>
> If you want bytes(5), use bytes(5) as default value. The literal 5 is a
> number, not a bytes string, and thus not a valid value for a variable typed
> as bytes.
>
>
>>> unless forbidden in Python 3.
>>
>> Read: Unless 'bytes(5)' etc. is forbidden in Python 3. ;)
>
> I hope you are aware that bytes(5) is not str(5):
>
>    Python 3.1.1 (r311:74480, Oct 22 2009, 19:34:26)
>    [GCC 4.3.2] on linux2
>    Type "help", "copyright", "credits" or "license" for more information.
>    >>> bytes(5)
>    b'\x00\x00\x00\x00\x00'
>    >>> str(5)
>    '5'
>
> That's one of the differences between the Py2.6 bytes/str type and the
> 'real' Py3.x bytes type, BTW.
>

Just other thing we should workaround to alleviate users from the
diferences? So bytes(n) would give at b"\0"*n in both Py2/Py3 ? note:
only bytes(n), not for str(n)



-- 
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to