On Thursday 14 April 2011 21:39:14 Eli Stevens (Gmail) wrote: > Ints on windows round-trip just fine too, AFAICT. > > From my PoV, the most important things are, in decreasing order of > importance: > > 1. Consistent behavior across platforms (windows, OSX, etc.).
This exists right now.
> 2. Clean roundtripping behavior (silently taking False and turning it
> into u'false' -- a true value in python! -- is very dangerous). I'd
> rather get a ValueError when trying to set the value than have it get
> silently coerced to a string like that.
You need to understand that the problem isn't in PySide itself, the problem is
in Qt that stores every type as string in QSettings no matter if it's a bool,
a int, etc..
We can't fix this at PySide level, because there's no way to guess the
semantic of an value based only on their contents, e.g.
s = QSettings(...)
s.setValue("key1", "2")
a = s.value("key1")
There's no way to guess if the user want the type of key1 to be an int 2 or a
string "2" because we lost the type info after the setValue method call.
Trying to coerce everything to int, float and double before returning a string
will turn the QSettings.value function into a wild horse that can return
anything depending on the contents, if the contents aren't controlled by you,
e.g. some input got from an user, you will need to always cast the output for
safeness.
The only solution would be have QSettings storing the type, so the value()
method would return a QVariant with correct type instead of always returning a
QVariant storing a string, but I doubt the Qt guys will accept such behavior
change at this time.
> 3. Consistent behavior between the program invocation where the
> setting was set, and the invocation where it is read. In my case, the
> errors didn't appear until the *second* time I ran the program.
If you want to catch the errors at compile time you are using the wrong tool,
think about C++, Java or C#.
> 4. Consistency with similar API calls from C++.
C++ have QVariants and QStrings, PySide and PyQt (API2) not, and IMO back with
QVariant and QStrings would be a huge step backwards, the Python code without
those classes are much more simpler and ease to read and write.
BTW, in PyQt API1 you write s.value().toInt(), now you write int(s.value()),
not much different IMO. I agree that with booleans is a bit more boring,
because instead of writting s.value().toBool() you write s.value() == "false",
anyway it's not a big deal IMO.
> 5. Consistency with similar API calls from PyQt.
This exists right now, if you use PyQt API2 you will get the unicodes as well.
> Note that I think that 1 and 2 are much more important than 4 or 5.
I know, but hope the get the my points a bit clearer.
--
Hugo Parente Lima
INdT - Instituto Nokia de Tecnologia
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ PySide mailing list [email protected] http://lists.pyside.org/listinfo/pyside
