On 2010-04-20, Matti Airas wrote:
> On 20.04.2010 17:43, ext Mark Summerfield wrote:
> > Seems good to me. However, there needs to be a decision about whether to
> > provide the QVariant(type, object) factory function or static
> > QVariant.type() methods. I prefer the factory function.
> 
> Oops, should've read more carefully. *blushes*
> 
> > Also, I should have written them my Pythonically (rather than like
> > C++!):
> >
> >      # static functions approach
> >      QVariant.ushort(pythonObject) ->  QVariant
> >      QVariant.uint(pythonObject) ->  QVariant
> >
> >      # factory function approach (based on Richard Dale's ideas)
> >      QVariant("ushort", pythonObject) ->  QVariant
> >      QVariant("uint", pythonObject) ->  QVariant
> 
> Applied this.
> 
> I have to say I still prefer the former approach. It gives a fighting
> chance to syntactic checkers (as in IDEs) to detect typos and other
> errors. Also, since the underlying Qt QVariant only accepts a limited
> number of types and probably won't change too much (if at all), the
> increased versatility would be kinda wasted (if I have understood
> correctly).
> 
> Furthermore, static functions is the method PyQt already uses, and if
> there are no significant advantages in either syntax, I think we ought
> to pick the more comformant one. I'd even go as far to change the
> function names as follows:
> 
>      QVariant.fromUInt(pythonObject) -> QVariant
> 
> It's a bit uglier but that's the syntax PyQt already uses and the names
> would be identical to QVariant.Type constants.
> 
> But then again, I'm hardly experienced enough on PyQt/PySide programming
> to have strong opinions about this one.

Your solution seems reasonable to me. I also like the idea of using the
QVariant.Type names.

Regarding error checking, I assume that :

    functionThatTakesAVariant(QVariant.fromInt("123"))

will raise a TypeError (in the QVariant.fromInt() call) or some other
exception? Whereas:

    functionThatTakesAVariant("123")

is fine ("123" becomes a QVariant holding a QString behind the scenes)
relying on the automatic conversion. But if you try to cheat you get a
helpful exception.

-- 
Mark Summerfield, Qtrac Ltd, www.qtrac.eu
    C++, Python, Qt, PyQt - training and consultancy
        "C++ GUI Programming with Qt 4" - ISBN 0132354160
_______________________________________________
PySide mailing list
[email protected]
http://lists.openbossa.org/listinfo/pyside

Reply via email to