[Python-ideas] Simple class initialization

geremy condra debatem1 at gmail.com
Mon Apr 18 02:45:01 CEST 2011


On Sun, Apr 17, 2011 at 3:43 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Steven D'Aprano wrote:
>
>> That's not a bug, that's a feature.
>>
>> It's been stated many times by Guido that it's far too early to
>> standardize on a single meaning for annotations.
>
> I think it's a rather *strange* feature.
>
> Imagine what would happen if someone other than Guido
> proposed a syntax extension with no defined semantics
> and no use cases. I don't think it would be very well
> received!

I have a use case- I use them to wrap C functions using ctypes in a
semi-sane way.

Old way:

RAND_bytes = libraries['ssl'].RAND_bytes
RAND_bytes.restype = ctypes.c_int
RAND_bytes.argtypes = [ctypes.c_char_p, ctypes.c_int]

My way:

@C_function("ssl")
def RAND_bytes(iv: c_char_p, iv_length: c_int) -> c_int:
        return RAND_bytes.c_function(iv, iv_length)

IIRC, this came up during the initial discussion and wasn't widely
loved, but for me (I do a reasonable amount of glue work) it makes
life a lot simpler.

Geremy Condra



More information about the Python-ideas mailing list