[PyKDE] Re: PyKDE Digest, Vol 6, Issue 5

Chris Jones cdj at mail.lns.cornell.edu
Mon Jan 10 15:14:40 GMT 2005


It looks like a clarification of C++ is in order.
>>
>> I would expect that one can pass a Python int as well as a SIP-4.2 
>> enum
>> argument into an enum parameter of a function wrapped by SIP (a C++
>> function with a C++ enum parameter accepts C++ int arguments).

That is incorrect.  C++ will NOT accept an int when a function has an 
enum parameter.  However, if the function takes an int it WILL allow an 
enum.  This is because C++ will convert and enum into an int, but not 
an int into an enum.  This is part of its type safety features.


> Ok, I've had second thoughts about this - the idiom of oring enum 
> values is
> too common. Tonight's SIP snapshot will allow an integer whereever an 
> enum is
> expected. I can still get QListBox.setColumnMode() to work properly, 
> which
> was the original intent of the change.
>
The 'or'ing together of enums to form an argument to a function is 
common, but if you look, the function signature takes an 'int' and not 
the enum.  When this is done, the enum is just being used as a symbolic 
constant and its type is usually irrelevant.

So what may be needed is a way to explicitly coerce a python 'int' into 
an enum just like it is possible to cast an int into an enum in C++ 
(say a class method called 'intToEnum').  The explicit coercion would 
be a known 'dangerous thing to do' and if it failed, would be easy to 
find just by searching to code for the appropriate member function 
call.

If you do allow all enums to be replaced automatically by ints, you are 
opening a very large number of qt undefined run time errors that could 
have been caught by the python type checking of the arguments used.

	Chris Jones




More information about the PyQt mailing list